Artifact Content
Not logged in

Artifact 2ee706699e24611b7c26e2a9529eed1e5e3b7e10


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

static const unsigned MODVAL = 1000000007;
struct mint
{
	unsigned val;
	mint():val(0){}
	mint(int      x):val(x%MODVAL) {}
	mint(unsigned x):val(x%MODVAL) {}
	mint(LL       x):val(x%MODVAL) {}
};
mint& operator+=(mint& x, mint y) { return x = x.val+y.val; }
mint& operator-=(mint& x, mint y) { return x = x.val-y.val+MODVAL; }
mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; }
mint operator+(mint x, mint y) { return x+=y; }
mint operator-(mint x, mint y) { return x-=y; }
mint operator*(mint x, mint y) { return x*=y; }

mint POW(mint x, LL e) { mint v=1; for(;e;x*=x,e>>=1) if(e&1) v*=x; return v; }
mint& operator/=(mint& x, mint y) { return x *= POW(y, MODVAL-2); }
mint operator/(mint x, mint y) { return x/=y; }

class TaroFillingAStringDiv1 { public:
	int getNumber(int, vector <int> position, string value)
	{
		vector<pair<int,char>> sorted;
		for(int i=0; i<position.size(); ++i)
			sorted.emplace_back(position[i]-1, value[i]);
		sort(sorted.begin(), sorted.end());

		mint ans = 1;
		for(int i=1; i<sorted.size(); ++i)
			ans *= solve(sorted[i].first-sorted[i-1].first-1, sorted[i-1].second == sorted[i].second);
		return ans.val;
	}

	// 'A' + '?'*N + (same?'A':'B')
	mint solve(int N, bool same) {
		if(same && (N%2)==1)
			return 1;
		if(!same && (N%2)==0)
			return 1;
		return (N+1);
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const int& Expected, const int& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, TaroFillingAStringDiv1().getNumber(N, position, value));}
int main(){

CASE(0)
	int N = 3; 
	int position_[] = {1, 3};
	  vector <int> position(position_, position_+sizeof(position_)/sizeof(*position_)); 
	string value = "AB"; 
	int _ = 2; 
END
CASE(1)
	int N = 4; 
	int position_[] = {2, 1, 3, 4};
	  vector <int> position(position_, position_+sizeof(position_)/sizeof(*position_)); 
	string value = "ABBA"; 
	int _ = 1; 
END
CASE(2)
	int N = 25; 
	int position_[] = {23, 4, 8, 1, 24, 9, 16, 17, 6, 2, 25, 15, 14, 7, 13};
	  vector <int> position(position_, position_+sizeof(position_)/sizeof(*position_)); 
	string value = "ABBBBABABBAAABA"; 
	int _ = 1; 
END
CASE(3)
	int N = 305; 
	int position_[] = {183, 115, 250, 1, 188, 193, 163, 221, 144, 191, 92, 192, 58, 215, 157, 187, 227, 177, 206, 15, 272, 232, 49, 11, 178, 59, 189, 246};
	  vector <int> position(position_, position_+sizeof(position_)/sizeof(*position_)); 
	string value = "ABAABBABBAABABBBBAAAABBABBBA"; 
	int _ = 43068480; 
END
CASE(4)
	int N = 1000000000; 
	int position_[] = {183, 115, 250, 1, 188, 193, 163, 221, 144, 191, 92, 192, 58, 215, 157, 187, 227, 177, 206, 15, 272, 232, 49, 11, 178, 59, 189, 246};
	  vector <int> position(position_, position_+sizeof(position_)/sizeof(*position_)); 
	string value = "ABAABBABBAABABBBBAAAABBABBBA"; 
	int _ = -1; 
END
/*
CASE(5)
	int N = ; 
	int position_[] = ;
	  vector <int> position(position_, position_+sizeof(position_)/sizeof(*position_)); 
	string value = ; 
	int _ = ; 
END
*/
}
// END CUT HERE