Submission #501069

#TimeUsernameProblemLanguageResultExecution timeMemory
501069600MihneaMiners (IOI07_miners)C++17
100 / 100
111 ms101012 KiB
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 7; const int INF = (int) 1e9; int n; int type[N]; int dp[N][4][4][4][4]; int memo[4][4][4]; int main() { ios::sync_with_stdio(0); cin.tie(0); for (int a = 0; a < 4; a++) { for (int b = 0; b < 4; b++) { for (int c = 0; c < 4; c++) { set<int> s; s.insert(a); s.insert(b); s.insert(c); memo[a][b][c] = (int) s.size() - s.count(0); } } } { string s; cin >> n >> s; int Index = 0; map<char, int> MP; for (int i = 1; i <= n; i++) { char ch = s[i - 1]; if (!MP.count(ch)) { MP[ch] = ++Index; } type[i] = MP[ch]; } for (int i = 1; i <= n; i++) { assert(1 <= type[i] && type[i] <= 3); } } for (int i = 0; i < N; i++) { for (int a = 0; a < 4; a++) { for (int b = 0; b < 4; b++) { for (int c = 0; c < 4; c++) { for (int d = 0; d < 4; d++) { dp[i][a][b][c][d] = -INF; } } } } } dp[0][0][0][0][0] = 0; for (int i = 0; i < n; i++) { int x = type[i + 1]; for (int a = 0; a < 4; a++) { for (int b = 0; b < 4; b++) { for (int c = 0; c < 4; c++) { for (int d = 0; d < 4; d++) { dp[i + 1][a][b][d][x] = max(dp[i + 1][a][b][d][x], dp[i][a][b][c][d] + memo[c][d][x]); dp[i + 1][b][x][c][d] = max(dp[i + 1][b][x][c][d], dp[i][a][b][c][d] + memo[a][b][x]); } } } } } int sol = -1; for (int a = 0; a < 4; a++) { for (int b = 0; b < 4; b++) { for (int c = 0; c < 4; c++) { for (int d = 0; d < 4; d++) { sol = max(sol, dp[n][a][b][c][d]); } } } } cout << sol << "\n"; return 0; }
#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...