Submission #384445

# Submission time Handle Problem Language Result Execution time Memory
384445 2021-04-01T16:56:36 Z ak2006 Miners (IOI07_miners) C++14
100 / 100
845 ms 876 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
const ll mod = 1e9 + 7,inf = 1e18;
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int dp[2][4][4][4][4];
int main()
{
    fast;
    int n;
    cin>>n;
    vi a(n);
    for (int i = 0;i<n;i++){
        char x;
        cin>>x;
        if (x == 'M')a[i] = 0;
        else if (x == 'F')a[i] = 1;
        else a[i] = 2;
    }
    for (int i = n - 1;i>=0;i--){
        for (int a1 = 3;a1>=0;a1--){
            for (int a2 = 3;a2>=0;a2--){
                for (int b1 = 3;b1>=0;b1--){
                    for (int b2 = 3;b2>=0;b2--){
                        int bon1 = 0,bon2 = 0;
                        vi f(4);

                        f[a[i]]++,f[a1]++,f[a2]++;
                        bon1 = (f[0] >= 1 ? 1 : 0) + (f[1] >= 1 ? 1 : 0) + (f[2] >= 1 ? 1 : 0);
                        f[0] = 0,f[1] = 0,f[2] = 0;
                        f[a[i]]++,f[b1]++,f[b2]++;
                        bon2 = (f[0] >= 1 ? 1 : 0) + (f[1] >= 1 ? 1 : 0) + (f[2] >= 1 ? 1 : 0);

                        if (i == n - 1)dp[i%2][a1][a2][b1][b2] = max(bon1,bon2);
                        else dp[i%2][a1][a2][b1][b2] = max(bon1 + dp[(i + 1)%2][a[i]][a1][b1][b2],bon2 + dp[(i + 1)%2][a1][a2][a[i]][b1]);
                    }
                }
            }
        }
    }
    cout<<dp[0][3][3][3][3];
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 85 ms 452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 213 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 642 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 845 ms 876 KB Output is correct