제출 #756642

#제출 시각아이디문제언어결과실행 시간메모리
756642SanguineChameleonMiners (IOI07_miners)C++17
100 / 100
126 ms101100 KiB
#include <bits/stdc++.h> using namespace std; void just_do_it(); int main() { #ifdef KAMIRULEZ freopen("kamirulez.inp", "r", stdin); freopen("kamirulez.out", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); just_do_it(); return 0; } const int maxn = 1e5 + 20; int a[maxn]; int dp[maxn][4][4][4][4]; int cnt(int x, int y, int z) { if (x == 0 && y == 0) { return 1; } if (x == 0) { if (y == z) { return 1; } else { return 2; } } if (x == y && y == z) { return 1; } if (x == y || y == z || z == x) { return 2; } return 3; } void just_do_it() { fill_n(&dp[0][0][0][0][0], maxn * 4 * 4 * 4 * 4, -1); int n; cin >> n; for (int i = 1; i <= n; i++) { char c; cin >> c; if (c == 'M') { a[i] = 1; } if (c == 'F') { a[i] = 2; } if (c == 'B') { a[i] = 3; } } dp[0][0][0][0][0] = 0; int res = 0; for (int i = 0; i < n; i++) { for (int x = 0; x < 4; x++) { for (int y = 0; y < 4; y++) { for (int z = 0; z < 4; z++) { for (int w = 0; w < 4; w++) { if (dp[i][x][y][z][w] == -1) { continue; } int t = a[i + 1]; dp[i + 1][y][t][z][w] = max(dp[i + 1][y][t][z][w], dp[i][x][y][z][w] + cnt(x, y, t)); dp[i + 1][x][y][w][t] = max(dp[i + 1][x][y][w][t], dp[i][x][y][z][w] + cnt(z, w, t)); res = max(res, dp[i + 1][y][t][z][w]); res = max(res, dp[i + 1][x][y][w][t]); } } } } } cout << res; }
#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...