답안 #406400

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
406400 2021-05-17T14:31:02 Z Lobo Miners (IOI07_miners) C++17
0 / 100
1500 ms 972 KB
#include <bits/stdc++.h>
 
using namespace std;

const long long INFll = 1e18;
const int INFii = 1e9;
const long long mod = (long long) 1e9 + 7;
typedef long long ll;
typedef int ii;
typedef double dbl;
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back

#define maxn 110000
//LEMBRAR DE MUDAR

ii n, s[maxn];
string S;
ii dp[2][4][4][4][4];

int main() {
    ios::sync_with_stdio(false); cin.tie(0);

    //freopen("in.in", "r", stdin);
    //freopen("__.out", "w", stdout);

    cin >> n;
    cin >> S;

    dp[0][0][0][0][0] = 0;

    for(ii i = 0; i < n; i++) {
        if(S[i] == 'M') s[i] = 1;
        if(S[i] == 'F') s[i] = 2;
        if(S[i] == 'B') s[i] = 3;
    }

    for(ii i = n; i >= 1; i--) {
        for(ii a1 = 0; a1 <= 4; a1++)
        for(ii a2 = 0; a2 <= 4; a2++) 
        for(ii b1 = 0; b1 <= 4; b1++) 
        for(ii b2 = 0; b2 <= 4; b2++) {

            set<ii> st1,st2;

            if(a1 != 0) st1.insert(a1);
            if(a2 != 0) st1.insert(a2);
            st1.insert(s[i]);
            ii p1 = st1.size();

            if(b1 != 0) st2.insert(b1);
            if(b2 != 0) st2.insert(b2);
            st2.insert(s[i]);
            ii p2 = st2.size();


            dp[i%2][a1][a2][b1][b2] = max(p1 + dp[(i+1)%2][s[i]][a1][b1][b2], p2 + dp[(i+1)%2][a1][a2][s[i]][b1]);

        }
    }

    cout << max({dp[n%2][s[1]][0][0][0], dp[n%2][0][s[1]][0][0], dp[n%2][0][0][s[1]][0], dp[n%2][0][0][0][s[1]]}) << endl;

}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 460 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 460 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 452 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 460 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 332 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 460 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 122 ms 448 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 615 ms 456 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1106 ms 500 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1595 ms 460 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1576 ms 844 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1563 ms 972 KB Time limit exceeded