제출 #650121

#제출 시각아이디문제언어결과실행 시간메모리
650121esomerMiners (IOI07_miners)C++17
100 / 100
863 ms512 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl "\n" const int MOD = 998244353; void solve(){ int n; cin >> n; string s; cin >> s; int dp[4][4][4][4]; for(int i = 0; i < 4; i++){ for(int j = 0; j < 4; j++){ for(int q = 0; q < 4; q++){ for(int l = 0; l < 4; l++){ dp[i][j][q][l] = -1; } } } } dp[0][0][0][0] = 0; for(int i = 0; i < n; i++){ int nw[4][4][4][4]; for(int k = 0; k < 4; k++){ for(int j = 0; j < 4; j++){ for(int q = 0; q < 4; q++){ for(int l = 0; l < 4; l++){ nw[k][j][q][l] = -1; } } } } for(int k = 0; k < 4; k++){ for(int j = 0; j < 4; j++){ for(int q = 0; q < 4; q++){ for(int l = 0; l < 4; l++){ if(dp[k][j][q][l] == -1) continue; pair<pair<int, int>, pair<int, int>> p = {{k, j}, {q, l}}; int c; if(s[i] == 'M') c = 1; else if(s[i] == 'F') c = 2; else c = 3; set<int> add; add.insert(c); add.insert(p.first.first); add.insert(p.first.second); add.erase(0); nw[p.first.second][c][p.second.first][p.second.second] = max(nw[p.first.second][c][p.second.first][p.second.second], dp[k][j][q][l] + (int)add.size()); add.clear(); add.insert(c); add.insert(p.second.first); add.insert(p.second.second); add.erase(0); nw[p.first.first][p.first.second][p.second.second][c] = max(nw[p.first.first][p.first.second][p.second.second][c], dp[k][j][q][l] + (int)add.size()); } } } } for(int k = 0; k < 4; k++){ for(int j = 0; j < 4; j++){ for(int q = 0; q < 4; q++){ for(int l = 0; l < 4; l++){ dp[k][j][q][l] = nw[k][j][q][l]; } } } } } int ans = 0; for(int k = 0; k < 4; k++){ for(int j = 0; j < 4; j++){ for(int q = 0; q < 4; q++){ for(int l = 0; l < 4; l++){ ans = max(ans, dp[k][j][q][l]); } } } } cout << ans << endl; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); //freopen("inpt.txt", "r", stdin); //freopen("out.txt", "w", stdout); //int tt; cin >> tt; int tt = 1; for(int t = 1; t <= tt; t++){ //cout << "Case #"<<t << ": "; solve(); } }
#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...