Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <cstdint>
- using namespace std;
- constexpr uint32_t M = 1000000007;
- constexpr int RPS2int(char c){
- switch( c){
- case 'R': return 0;break;
- case 'P': return 1;break;
- case 'S': return 2;break;
- default: return -1;
- };
- }
- int score (char our, char thier){
- int res = (RPS2int(our)-RPS2int(thier) +3 )%3;
- return ((1+res)%3)-1; //convert 2 into -1;
- }
- int main()
- {
- std::string enemy_move;
- cin>>enemy_move;
- int n = enemy_move.size();
- vector<uint32_t> R(2*n+3), P(2*n+3), S(2*n+3);
- vector<uint32_t> R_new(2*n+3), P_new(2*n+3), S_new(2*n+3);
- R[ n+1 + score('R',enemy_move[0])]=1;
- P[ n+1 + score('P',enemy_move[0])]=1;
- S[ n+1 + score('S',enemy_move[0])]=1;
- for (int t=1; t<enemy_move.size(); t++){
- R_new[0]=R_new.back()=0;
- S_new[0]=S_new.back()=0;
- P_new[0]=P_new.back()=0;
- for (int i=1; i<R.size()-1; i++){
- R_new[i] = (P[i-score('R',enemy_move[t])] + S[i-score('R',enemy_move[t])])%M;
- P_new[i] = (R[i-score('P',enemy_move[t])] + S[i-score('P',enemy_move[t])])%M;
- S_new[i] = (P[i-score('S',enemy_move[t])] + R[i-score('S',enemy_move[t])])%M;
- }
- swap(R,R_new);
- swap(P,P_new);
- swap(S,S_new);
- cout<<"round "<<t<<endl;
- }
- uint64_t accu=0;
- for (int i=n+2; i<R.size();i++){
- accu = (accu + R[i]+P[i]+S[i])%M;
- }
- cout<<accu<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement