//諸々include、namespace設定(ACLも使用可能) #include #include using namespace std; using namespace chrono; using namespace atcoder; using ll=unsigned long long; #define rep(i,n) for(int i=0; i<(int)(n); i++) //0以上2^32-1以下の整数をランダムに生成(xorshift32) //seed値を固定しているため、基本結果が上振れたり下振れたりしない unsigned int randxor(){ static unsigned int x=42; x=x^(x<<13);x=x^(x>>15);x=x^(x<<17); return x; } //l以上r以下の整数をランダムに生成 int randint(int l,int r){ return l+randxor()%(r-l+1); } //l以上r以下の実数をランダムに生成 double uniform(double l,double r){ return ((double)randxor()/UINT_MAX)*(r-l)+l; } //時間計測(ミリ秒)、秒に直す場合10^6で割ると得られる auto startTime=system_clock::now(); int getTime(){ return duration_cast(system_clock::now()-startTime).count(); } //ゲームをプレイする const vector behavior={"click","buy","sell","reinforce","enhclick"}; const vector facil={" hand"," lily"," factory"," casino"," grimoire",""}; const vector price={150,2000,30000,600000,10000000}; const vector prod={1,10,120,2000,25000}; int N; string S; struct game{ //評価関数:Nターンclickのみ行った場合のクッキーの枚数 ll cookie; int turn; ll clickprod; int discount; int fever; int mag; vector pos_number; vector rein; queue ans; game(){ turn=0; cookie=0; clickprod=1; discount=10; fever=0; mag=1; pos_number={0,0,0,0,0}; rein={1,1,1,1,1}; } void production(){ rep(i,5){ cookie+=prod[i]*pos_number[i]*rein[i]*mag; } discount=10; fever--; if(S[turn]=='B')cookie=(cookie*101+99)/100; else if(S[turn]=='F'){fever=20;mag=7;} else if(S[turn]=='S')discount=9; if(fever<=0)mag=1; turn++; } bool click(){ cookie+=clickprod*mag; ans.push(5); production(); return true; } bool buy(int kinds){ ll nowprice=price[kinds]; rep(i,pos_number[kinds]){ nowprice=(nowprice*6+4)/5; } if(cookie>=nowprice){ cookie-=nowprice; pos_number[kinds]++; production(); ans.push(6+kinds); return true; } return false; } bool sell(int kinds){ if(pos_number[kinds]>0){ ll nowprice=price[kinds]; pos_number[kinds]--; rep(i,pos_number[kinds]){ nowprice=(nowprice*6+4)/5; } cookie+=(nowprice+3)/4; production(); ans.push(12+kinds); return true; } return false; } bool reinforce(int kinds){ if(pos_number[kinds]>0){ ll nowprice=price[kinds]*10; ll cnt=1; while(cnt=nowprice){ rein[kinds]*=2; cookie-=nowprice; production(); ans.push(18+kinds); return true; } return false; } return false; } bool enhclick(){ ll nowprice=15; ll cnt=1; while(cnt=nowprice){ clickprod*=2; cookie-=nowprice; production(); ans.push(29); return true; } return false; } ll score(){ tuple pre={cookie,discount,fever,mag,turn}; rep(i,min(N-turn,500)){ cookie+=clickprod*mag; production(); } ll ret=cookie; tie(cookie,discount,fever,mag,turn)=pre; return ret; } void print(){ while(ans.size()>0){ int action=ans.front(); ans.pop(); cout<>reac; if(reac!="ok"){ cerr<>N; cin>>S; game g; rep(i,N){ game pre=g; pre.click(); ll score=pre.score(); game now=g; if(now.enhclick()){ if(score