Submission #831803

# Submission time Handle Problem Language Result Execution time Memory
831803 2023-08-20T15:27:22 Z Kerim Miners (IOI07_miners) C++17
100 / 100
66 ms 468 KB
#include "bits/stdc++.h"
#define pb(x) push_back(x)
using namespace std;
const int N = 1e5+5;
const int INF = 1e9+10;
char s[N];
int bit[] = {0, 1, 1, 2, 1, 2, 2, 3};
int dp[4][4][4][4], odp[4][4][4][4];
int f(int x, int y, int z){
    int mask = 0;
    if (x) mask |= (1<<(x-1));
    if (y) mask |= (1<<(y-1));
    if (z) mask |= (1<<(z-1));
    return bit[mask];
}
int main(){
    // freopen("file.in", "r", stdin);
    // freopen("file.out", "w", stdout);
    int n, c;
    scanf("%d", &n);
    scanf("%s", s);
    for (int x = 0; x < 4; x++)
        for (int y = 0; y < 4; y++)
            for (int xp = 0; xp < 4; xp++)
                for (int yp = 0; yp < 4; yp++)
                    dp[x][y][xp][yp] = -INF;
    dp[0][0][0][0] = 0;
    for (int i = 0; i < n; i++){
        for (int x = 0; x < 4; x++)
            for (int y = 0; y < 4; y++)
                for (int xp = 0; xp < 4; xp++)
                    for (int yp = 0; yp < 4; yp++)
                        odp[x][y][xp][yp] = -INF;
        if (s[i] == 'M') c = 1;
        else if(s[i] == 'F') c = 2;
        else c = 3;
        for (int x = 0; x < 4; x++)
            for (int y = 0; y < 4; y++)
                for (int xp = 0; xp < 4; xp++)
                    for (int yp = 0; yp < 4; yp++){
                        odp[y][c][xp][yp] = max(odp[y][c][xp][yp], dp[x][y][xp][yp] + f(x, y, c));
                        odp[x][y][yp][c] = max(odp[x][y][yp][c], dp[x][y][xp][yp] + f(xp, yp, c));
                    }
        memcpy(dp, odp, sizeof dp);
    }
    int answer = 0;
    for (int x = 0; x < 4; x++)
        for (int y = 0; y < 4; y++)
            for (int xp = 0; xp < 4; xp++)
                for (int yp = 0; yp < 4; yp++)
                    answer = max(answer, dp[x][y][xp][yp]);
    printf("%d\n", answer);
}

Compilation message

miners.cpp: In function 'int main()':
miners.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
miners.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     scanf("%s", s);
      |     ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 468 KB Output is correct