Submission #100681

# Submission time Handle Problem Language Result Execution time Memory
100681 2019-03-13T09:11:58 Z muradeyn Miners (IOI07_miners) C++14
100 / 100
333 ms 1076 KB
/* Murad Eynizade */

#include <bits/stdc++.h>
#define intt long long
#define FAST_READ ios_base::sync_with_stdio(0);cin.tie(0);
#define F first
#define S second

using namespace std;

const int sz = 100005;

int n , ty[sz] , dp[2][4][4][4][4];

string s;

int val(int a,int b,int c) {
    int ret = 0;
    for (int i = 1;i<4;i++)
        if (a == i || b == i || c == i)ret++;
    return ret;
}

int main()
{
    FAST_READ;
    cin>>n>>s;
    for (int i = 0;i<n;i++) {
        if (s[i] == 'M')ty[i] = 1;
        if (s[i] == 'B')ty[i] = 2;
        if (s[i] == 'F')ty[i] = 3;
    }
    int nw = 0 , old = 1;
    for (int w = n - 1;w>=0;w--) {
        old = 1 - old;
        nw = 1 - nw;
        for (int i = 0;i<4;i++)
            for (int j = 0;j<4;j++)
                for (int k = 0;k<4;k++)
                    for (int c = 0;c < 4;c++)
                        dp[nw][i][j][k][c] = max(dp[old][j][ty[w]][k][c] + val(i , j , ty[w]) , dp[old][i][j][c][ty[w]] + val(k,c,ty[w]));

    }
    cout<<dp[nw][0][0][0][0]<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 255 ms 936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 333 ms 1076 KB Output is correct