Submission #1136800

#TimeUsernameProblemLanguageResultExecution timeMemory
1136800toast12Miners (IOI07_miners)C++20
100 / 100
889 ms447480 KiB
#include <bits/stdc++.h>
using namespace std;

map<char, int> m;
int n;
string s;
vector<vector<vector<vector<vector<int>>>>> dp;

int calc(int a, int b, int c) {
    if (a == 0 || b == 0 || c == 0) {
        if (a == 0) {
            if (b == 0) {
                if (c == 0) return 0;
                else return 1;
            }
            else {
                if (c == 0) return 1;
                else if (b == c) return 1;
                else return 2;
            }
        }
        else {
            if (b == 0) {
                if (c == 0) return 1;
                else if (a == c) return 1;
                else return 2;
            }
            else {
                if (c == 0) {
                    if (a == b) return 1;
                    else return 2;
                }
                else {
                    if (a == b) {
                        if (b == c) return 1;
                        else return 2;
                    }
                    else {
                        if (a == c) return 2;
                        else {
                            if (b == c) return 2;
                            else return 3;
                        }
                    }
                }
            }
        }
    }
    else {
        if (a == b) {
            if (b == c) return 1;
            else return 2;
        }
        else {
            if (a == c) return 2;
            else {
                if (b == c) return 2;
                else return 3;
            }
        }
    }
}

int solve(int i, int a1, int a2, int b1, int b2) {
    if (i == n) return 0;
    if (dp[i][a1][a2][b1][b2] != -1) return dp[i][a1][a2][b1][b2];
    int ans = 0;
    // send this to mine a
    ans = max(ans, solve(i+1, a2, m[s[i]], b1, b2)+calc(a1, a2, m[s[i]]));
    // send it to mine b
    ans = max(ans, solve(i+1, a1, a2, b2, m[s[i]])+calc(b1, b2, m[s[i]]));
    return dp[i][a1][a2][b1][b2] = ans;
}

int main() {
    cin >> n >> s;
    dp.resize(n+1, vector<vector<vector<vector<int>>>>(4, vector<vector<vector<int>>>(4, vector<vector<int>>(4, vector<int>(4, -1)))));
    m['M'] = 1;
    m['F'] = 2;
    m['B'] = 3;
    cout << solve(0, 0, 0, 0, 0) << '\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...