Advertisement
Josif_tepe

Untitled

Feb 3rd, 2024
618
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <vector>
  4. #include <cstring>
  5. #include <set>
  6. //#include<bits/stdc++.h>
  7. using namespace std;
  8. const int INF = 2e9;
  9. typedef long long ll;
  10. int n;
  11. string s;
  12. int dp[2][4][4][4][4];
  13. int main() {
  14.     ios_base::sync_with_stdio(false);
  15.     cin >> n >> s;
  16.     for(int at = 0; at < 2; at++) {
  17.         for(int l1 = 0; l1 <= 3; l1++) {
  18.             for(int l2 = 0; l2 <= 3; l2++) {
  19.                 for(int r1 = 0; r1 <= 3; r1++) {
  20.                     for(int r2 = 0; r2 <= 3; r2++) {
  21.                         dp[at][l1][l2][r1][r2] = -INF;
  22.                        
  23.                     }
  24.                 }
  25.            
  26.         }
  27.     }
  28.     }
  29.     dp[0][0][0][0][0] = 0;
  30.     for(int at = 0; at < n; at++) {
  31.         for(int l1 = 0; l1 <= 3; l1++) {
  32.             for(int l2 = 0; l2 <= 3; l2++) {
  33.                 for(int r1 = 0; r1 <= 3; r1++) {
  34.                     for(int r2 = 0; r2 <= 3; r2++) {
  35.                         int now = at % 2;
  36.                         int next = 1 - now;
  37.                         int color = 0;
  38.                         if(s[at] == 'G') {
  39.                             color = 1;
  40.                         }
  41.                         else if(s[at] == 'R') {
  42.                             color = 2;
  43.                         }
  44.                         else {
  45.                             color = 3;
  46.                         }
  47.                         vector<bool> visited(4, false);
  48.                         visited[l1] = true;
  49.                         visited[l2] = true;
  50.                         visited[color] = true;
  51.                         int score = visited[1] + visited[2] + visited[3];
  52.                         dp[next][color][l1][r1][r2] = max(dp[now][l1][l2][r1][r2] + score, dp[next][color][l1][r1][r2]);
  53.                        
  54.                         visited[1] = false;
  55.                         visited[2] = false;
  56.                         visited[3] = false;
  57.                        
  58.                         visited[r1] = true;
  59.                         visited[r2] = true;
  60.                         visited[color] = true;
  61.                         score = visited[1] + visited[2] + visited[3];
  62.                        
  63.                         dp[next][l1][l2][color][r1] = max(dp[next][l1][l2][color][r1], dp[now][l1][l2][r1][r2] + score);
  64.                        
  65.                     }
  66.                 }
  67.             }
  68.         }
  69.    
  70.     }
  71.     int res = 0;
  72.     for(int at = 0; at < 2; at++) {
  73.         for(int l1 = 0; l1 <= 3; l1++) {
  74.             for(int l2 = 0; l2 <= 3; l2++) {
  75.                 for(int r1 = 0; r1 <= 3; r1++) {
  76.                     for(int r2 = 0; r2 <= 3; r2++) {
  77.                         res = max(res, dp[at][l1][l2][r1][r2]);
  78.                     }
  79.                 }
  80.             }
  81.         }
  82.     }
  83.     cout << res << endl;
  84.     return 0;
  85. }
  86.  
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement