제출 #306331

#제출 시각아이디문제언어결과실행 시간메모리
306331sofapudenMiners (IOI07_miners)C++14
100 / 100
1243 ms100728 KiB
#include <bits/stdc++.h> using namespace std; int dp[100005][4][4][4][4]; int main(){ int n; cin >> n; memset(dp,0,sizeof dp); dp[0][0][0][0][0] = 1; for(int x = 0; x < n; ++x){ char c; cin >> c; int val = 0; if(c == 'M')val = 1; if(c == 'B')val = 2; if(c == 'F')val = 3; for(int i = 0; i < 4; ++i){ for(int j = 0; j < 4; ++j){ for(int k = 0; k < 4; ++k){ for(int l = 0; l < 4; ++l){ if(!dp[x][i][j][k][l])continue; set<int> ans1, ans2; ans1.insert(i); ans1.insert(j); ans1.insert(val); ans2.insert(k); ans2.insert(l); ans2.insert(val); ans1.erase(0); ans2.erase(0); dp[x+1][j][val][k][l] = max(dp[x+1][j][val][k][l], dp[x][i][j][k][l]+(int)ans1.size()); dp[x+1][i][j][l][val] = max(dp[x+1][i][j][l][val], dp[x][i][j][k][l]+(int)ans2.size()); } } } } } int ans = 0; for(int i = 0; i < 4; ++i){ for(int j = 0; j < 4; ++j){ for(int k = 0; k < 4; ++k){ for(int l = 0; l < 4; ++l){ ans = max(ans, dp[n][i][j][k][l]); } } } } cout << ans-1 << "\n"; }
#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...