Submission #1151035

#TimeUsernameProblemLanguageResultExecution timeMemory
1151035btninhMiners (IOI07_miners)C++20
0 / 100
1 ms328 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 100005;
const int mod = 1e9 + 7;

int n, a[N], dp[N][3][3][3][3];

int cost(int a, int b, int c){
    int cnt = 0;
    if (a == 0 || b == 0 || c == 0) ++cnt;
    if (a == 1 || b == 1 || c == 1) ++cnt;
    if (a == 2 || b == 2 || c == 2) ++cnt;
    return cnt;
}

signed main(){
    freopen("test.inp","r",stdin);
    freopen("test.out","w",stdout);
    ios::sync_with_stdio(0); cin.tie(0);
    
    cin >> n;
    for(int i = 1; i <= n; ++i){
        char c; cin >> c;
        if (c == 'M') a[i] = 0;
        if (c == 'F') a[i] = 1;
        if (c == 'B') a[i] = 2;
    }
    for(int i = 0; i <= n; ++i)
        for(int j1 = 0; j1 < 3; ++j1)
            for(int j2 = 0; j2 < 3; ++j2)
                for(int k1 = 0; k1 < 3; ++k1)
                    for(int k2 = 0; k2 < 3; ++k2) dp[i][j1][j2][k1][k2] = -1e18;
    
    dp[1][a[1]][a[1]][a[1]][a[1]] = 1;
    dp[2][a[2]][a[1]][a[1]][a[1]] = dp[2][a[1]][a[1]][a[2]][a[1]]= (a[1] != a[2] ? 2 : 1);
    for(int i = 3; i <= n; ++i){
        for(int j1 = 0; j1 < 3; ++j1){
            for(int j2 = 0; j2 < 3; ++j2){
                for(int k1 = 0; k1 < 3; ++k1){
                    for(int k2 = 0; k2 < 3; ++k2){
                        int cst1 = cost(a[i], j1, j2),
                            cst2 = cost(a[i], k1, k2);
                        dp[i][a[i]][j1][k1][k2] = max(dp[i][a[i]][j1][k1][k2], dp[i-1][j1][j2][k1][k2] + cst1);
                        dp[i][j1][j2][a[i]][k1] = max(dp[i][j1][j2][a[i]][k1], dp[i-1][j1][j2][k1][k2] + cst2);
                    }
                }
            }
        }
    }
    int ans = 0;
    for(int j1 = 0; j1 < 3; ++j1)
        for(int j2 = 0; j2 < 3; ++j2)
            for(int k1 = 0; k1 < 3; ++k1)
                for(int k2 = 0; k2 < 3; ++k2) ans = max({ans, dp[n][a[n]][j1][k1][k2], dp[n][j1][j2][a[n]][k1]});
    cout << ans;
}

Compilation message (stderr)

miners.cpp: In function 'int main()':
miners.cpp:18:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     freopen("test.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
miners.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     freopen("test.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...