Advertisement
bartekltg

rock paper scisors

Feb 25th, 2024
862
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <cstdint>
  5.  
  6.  
  7. using namespace std;
  8.  
  9. constexpr uint32_t M = 1000000007;
  10.  
  11. constexpr int RPS2int(char c){
  12.     switch( c){
  13.     case 'R': return 0;break;
  14.     case 'P': return 1;break;
  15.     case 'S': return 2;break;
  16.     default: return -1;
  17.     };
  18. }
  19.  
  20. int score (char our, char thier){
  21.     int res = (RPS2int(our)-RPS2int(thier) +3 )%3;
  22.     return ((1+res)%3)-1;  //convert 2 into -1;
  23. }
  24.  
  25.  
  26. int main()
  27. {
  28.     std::string enemy_move;
  29.  
  30.     cin>>enemy_move;
  31.  
  32.     int n = enemy_move.size();
  33.  
  34.     vector<uint32_t> R(2*n+3), P(2*n+3), S(2*n+3);
  35.     vector<uint32_t> R_new(2*n+3), P_new(2*n+3), S_new(2*n+3);
  36.  
  37.  
  38.     R[ n+1 + score('R',enemy_move[0])]=1;
  39.     P[ n+1 + score('P',enemy_move[0])]=1;
  40.     S[ n+1 + score('S',enemy_move[0])]=1;
  41.  
  42.     for (int t=1; t<enemy_move.size(); t++){
  43.         R_new[0]=R_new.back()=0;
  44.         S_new[0]=S_new.back()=0;
  45.         P_new[0]=P_new.back()=0;
  46.         for (int i=1; i<R.size()-1; i++){
  47.             R_new[i] = (P[i-score('R',enemy_move[t])] + S[i-score('R',enemy_move[t])])%M;
  48.             P_new[i] = (R[i-score('P',enemy_move[t])] + S[i-score('P',enemy_move[t])])%M;
  49.             S_new[i] = (P[i-score('S',enemy_move[t])] + R[i-score('S',enemy_move[t])])%M;
  50.         }
  51.         swap(R,R_new);
  52.         swap(P,P_new);
  53.         swap(S,S_new);
  54.         cout<<"round "<<t<<endl;
  55.     }
  56.  
  57.     uint64_t accu=0;
  58.     for (int i=n+2; i<R.size();i++){
  59.         accu = (accu + R[i]+P[i]+S[i])%M;
  60.     }
  61.     cout<<accu<<endl;
  62.  
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement