Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <vector>
- #include <cstring>
- using namespace std;
- int n;
- string a;
- int memo[2][4][4][4][4];
- int main() {
- cin >> n;
- cin >> a;
- for(int i = 0; i < 2; i++) {
- for(int l1 = 0; l1 < 4; l1++) {
- for(int l2 = 0; l2 < 4; l2++) {
- for(int r1 = 0; r1 < 4; r1++) {
- for(int r2 = 0; r2 < 4; r2++) {
- memo[i][l1][l2][r1][r2] = -2e9;
- }
- }
- }
- }
- }
- memo[0][0][0][0][0] = 0;
- for(int i = 0; i < n; i++) {
- for(int l1 = 0; l1 < 4; l1++) {
- for(int l2 = 0; l2 < 4; l2++) {
- for(int r1 = 0; r1 < 4; r1++) {
- for(int r2 = 0; r2 < 4; r2++) {
- int now = i % 2;
- int next = 1 - now;
- vector<bool> visited(4, false);
- int color;
- if(a[i] == 'R') {
- color = 1;
- }
- else if(a[i] == 'Y') {
- color = 2;
- }
- else {
- color = 3;
- }
- visited[color] = true;
- visited[l1] = true;
- visited[l2] = true;
- int score = visited[1] + visited[2] + visited[3];
- memo[next][color][l1][r1][r2] = max(memo[next][color][l1][r1][r2], memo[now][l1][l2][r1][r2] + score);
- visited[1] = false;
- visited[2] = false;
- visited[3] = false;
- visited[color] = true;
- visited[r1] = true;
- visited[r2] = true;
- score = visited[1] + visited[2] + visited[3];
- memo[next][l1][l2][color][r1] = max(memo[next][l1][l2][color][r1], memo[now][l1][l2][r1][r2] + score);
- }
- }
- }
- }
- }
- int result = 0;
- for(int i = 0; i < 2; i++) {
- for(int l1 = 0; l1 < 4; l1++) {
- for(int l2 = 0; l2 < 4; l2++) {
- for(int r1 = 0; r1 < 4; r1++) {
- for(int r2 = 0; r2 < 4; r2++) {
- result = max(result, memo[i][l1][l2][r1][r2]);
- }
- }
- }
- }
- }
- cout << result << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement