e73fe40bab 2015-03-09 kinaba: #include <iostream> e73fe40bab 2015-03-09 kinaba: #include <sstream> e73fe40bab 2015-03-09 kinaba: #include <iomanip> e73fe40bab 2015-03-09 kinaba: #include <vector> e73fe40bab 2015-03-09 kinaba: #include <string> e73fe40bab 2015-03-09 kinaba: #include <map> e73fe40bab 2015-03-09 kinaba: #include <set> e73fe40bab 2015-03-09 kinaba: #include <algorithm> e73fe40bab 2015-03-09 kinaba: #include <numeric> e73fe40bab 2015-03-09 kinaba: #include <iterator> e73fe40bab 2015-03-09 kinaba: #include <functional> e73fe40bab 2015-03-09 kinaba: #include <complex> e73fe40bab 2015-03-09 kinaba: #include <queue> e73fe40bab 2015-03-09 kinaba: #include <stack> e73fe40bab 2015-03-09 kinaba: #include <cmath> e73fe40bab 2015-03-09 kinaba: #include <cassert> e73fe40bab 2015-03-09 kinaba: #include <tuple> e73fe40bab 2015-03-09 kinaba: using namespace std; e73fe40bab 2015-03-09 kinaba: typedef long long LL; e73fe40bab 2015-03-09 kinaba: typedef complex<double> CMP; e73fe40bab 2015-03-09 kinaba: e73fe40bab 2015-03-09 kinaba: static const unsigned MODVAL = 1000000007; e73fe40bab 2015-03-09 kinaba: struct mint e73fe40bab 2015-03-09 kinaba: { e73fe40bab 2015-03-09 kinaba: unsigned val; e73fe40bab 2015-03-09 kinaba: mint():val(0){} e73fe40bab 2015-03-09 kinaba: mint(int x):val(x%MODVAL) {} e73fe40bab 2015-03-09 kinaba: mint(unsigned x):val(x%MODVAL) {} e73fe40bab 2015-03-09 kinaba: mint(LL x):val(x%MODVAL) {} e73fe40bab 2015-03-09 kinaba: }; e73fe40bab 2015-03-09 kinaba: mint& operator+=(mint& x, mint y) { return x = x.val+y.val; } e73fe40bab 2015-03-09 kinaba: mint& operator-=(mint& x, mint y) { return x = x.val-y.val+MODVAL; } e73fe40bab 2015-03-09 kinaba: mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; } e73fe40bab 2015-03-09 kinaba: mint operator+(mint x, mint y) { return x+=y; } e73fe40bab 2015-03-09 kinaba: mint operator-(mint x, mint y) { return x-=y; } e73fe40bab 2015-03-09 kinaba: mint operator*(mint x, mint y) { return x*=y; } e73fe40bab 2015-03-09 kinaba: e73fe40bab 2015-03-09 kinaba: mint POW(mint x, LL e) { mint v=1; for(;e;x*=x,e>>=1) if(e&1) v*=x; return v; } e73fe40bab 2015-03-09 kinaba: mint& operator/=(mint& x, mint y) { return x *= POW(y, MODVAL-2); } e73fe40bab 2015-03-09 kinaba: mint operator/(mint x, mint y) { return x/=y; } e73fe40bab 2015-03-09 kinaba: e73fe40bab 2015-03-09 kinaba: class TaroFillingAStringDiv1 { public: e73fe40bab 2015-03-09 kinaba: int getNumber(int, vector <int> position, string value) e73fe40bab 2015-03-09 kinaba: { e73fe40bab 2015-03-09 kinaba: vector<pair<int,char>> sorted; e73fe40bab 2015-03-09 kinaba: for(int i=0; i<position.size(); ++i) e73fe40bab 2015-03-09 kinaba: sorted.emplace_back(position[i]-1, value[i]); e73fe40bab 2015-03-09 kinaba: sort(sorted.begin(), sorted.end()); e73fe40bab 2015-03-09 kinaba: e73fe40bab 2015-03-09 kinaba: mint ans = 1; e73fe40bab 2015-03-09 kinaba: for(int i=1; i<sorted.size(); ++i) e73fe40bab 2015-03-09 kinaba: ans *= solve(sorted[i].first-sorted[i-1].first-1, sorted[i-1].second == sorted[i].second); e73fe40bab 2015-03-09 kinaba: return ans.val; e73fe40bab 2015-03-09 kinaba: } e73fe40bab 2015-03-09 kinaba: e73fe40bab 2015-03-09 kinaba: // 'A' + '?'*N + (same?'A':'B') e73fe40bab 2015-03-09 kinaba: mint solve(int N, bool same) { e73fe40bab 2015-03-09 kinaba: if(same && (N%2)==1) e73fe40bab 2015-03-09 kinaba: return 1; e73fe40bab 2015-03-09 kinaba: if(!same && (N%2)==0) e73fe40bab 2015-03-09 kinaba: return 1; e73fe40bab 2015-03-09 kinaba: return (N+1); e73fe40bab 2015-03-09 kinaba: } e73fe40bab 2015-03-09 kinaba: }; e73fe40bab 2015-03-09 kinaba: e73fe40bab 2015-03-09 kinaba: // BEGIN CUT HERE e73fe40bab 2015-03-09 kinaba: #include <ctime> e73fe40bab 2015-03-09 kinaba: double start_time; string timer() e73fe40bab 2015-03-09 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } e73fe40bab 2015-03-09 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) e73fe40bab 2015-03-09 kinaba: { os << "{ "; e73fe40bab 2015-03-09 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) e73fe40bab 2015-03-09 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } e73fe40bab 2015-03-09 kinaba: void verify_case(const int& Expected, const int& Received) { e73fe40bab 2015-03-09 kinaba: bool ok = (Expected == Received); e73fe40bab 2015-03-09 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; e73fe40bab 2015-03-09 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } e73fe40bab 2015-03-09 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); e73fe40bab 2015-03-09 kinaba: #define END verify_case(_, TaroFillingAStringDiv1().getNumber(N, position, value));} e73fe40bab 2015-03-09 kinaba: int main(){ e73fe40bab 2015-03-09 kinaba: e73fe40bab 2015-03-09 kinaba: CASE(0) e73fe40bab 2015-03-09 kinaba: int N = 3; e73fe40bab 2015-03-09 kinaba: int position_[] = {1, 3}; e73fe40bab 2015-03-09 kinaba: vector <int> position(position_, position_+sizeof(position_)/sizeof(*position_)); e73fe40bab 2015-03-09 kinaba: string value = "AB"; e73fe40bab 2015-03-09 kinaba: int _ = 2; e73fe40bab 2015-03-09 kinaba: END e73fe40bab 2015-03-09 kinaba: CASE(1) e73fe40bab 2015-03-09 kinaba: int N = 4; e73fe40bab 2015-03-09 kinaba: int position_[] = {2, 1, 3, 4}; e73fe40bab 2015-03-09 kinaba: vector <int> position(position_, position_+sizeof(position_)/sizeof(*position_)); e73fe40bab 2015-03-09 kinaba: string value = "ABBA"; e73fe40bab 2015-03-09 kinaba: int _ = 1; e73fe40bab 2015-03-09 kinaba: END e73fe40bab 2015-03-09 kinaba: CASE(2) e73fe40bab 2015-03-09 kinaba: int N = 25; e73fe40bab 2015-03-09 kinaba: int position_[] = {23, 4, 8, 1, 24, 9, 16, 17, 6, 2, 25, 15, 14, 7, 13}; e73fe40bab 2015-03-09 kinaba: vector <int> position(position_, position_+sizeof(position_)/sizeof(*position_)); e73fe40bab 2015-03-09 kinaba: string value = "ABBBBABABBAAABA"; e73fe40bab 2015-03-09 kinaba: int _ = 1; e73fe40bab 2015-03-09 kinaba: END e73fe40bab 2015-03-09 kinaba: CASE(3) e73fe40bab 2015-03-09 kinaba: int N = 305; e73fe40bab 2015-03-09 kinaba: 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}; e73fe40bab 2015-03-09 kinaba: vector <int> position(position_, position_+sizeof(position_)/sizeof(*position_)); e73fe40bab 2015-03-09 kinaba: string value = "ABAABBABBAABABBBBAAAABBABBBA"; e73fe40bab 2015-03-09 kinaba: int _ = 43068480; e73fe40bab 2015-03-09 kinaba: END e73fe40bab 2015-03-09 kinaba: CASE(4) e73fe40bab 2015-03-09 kinaba: int N = 1000000000; e73fe40bab 2015-03-09 kinaba: 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}; e73fe40bab 2015-03-09 kinaba: vector <int> position(position_, position_+sizeof(position_)/sizeof(*position_)); e73fe40bab 2015-03-09 kinaba: string value = "ABAABBABBAABABBBBAAAABBABBBA"; e73fe40bab 2015-03-09 kinaba: int _ = -1; e73fe40bab 2015-03-09 kinaba: END e73fe40bab 2015-03-09 kinaba: /* e73fe40bab 2015-03-09 kinaba: CASE(5) e73fe40bab 2015-03-09 kinaba: int N = ; e73fe40bab 2015-03-09 kinaba: int position_[] = ; e73fe40bab 2015-03-09 kinaba: vector <int> position(position_, position_+sizeof(position_)/sizeof(*position_)); e73fe40bab 2015-03-09 kinaba: string value = ; e73fe40bab 2015-03-09 kinaba: int _ = ; e73fe40bab 2015-03-09 kinaba: END e73fe40bab 2015-03-09 kinaba: */ e73fe40bab 2015-03-09 kinaba: } e73fe40bab 2015-03-09 kinaba: // END CUT HERE