Submission #739590

#TimeUsernameProblemLanguageResultExecution timeMemory
739590ToxtaqMiners (IOI07_miners)C++17
100 / 100
1374 ms424648 KiB
#include<bits/stdc++.h> using namespace std; int n; string s; /// M-1, B-2, F-3 map<char, int>mp; long long table[100001][2][4][4][4][4]; long long rec(int indx, int mine, int last11, int last12, int last21, int last22){ vector<int>v(4); v[0] = last11; v[1] = last12; v[2] = last21; v[3] = last22; long long res = 0; int cnt = 0; vector<int>tempo(4); if(indx == n)return 0; if(table[indx][mine][last11][last12][last21][last22] != -1e18)return table[indx][mine][last11][last12][last21][last22]; if(mine == 1){ if(last11 != 0){ tempo[last11]++; cnt++; } if(last12 != 0){ if(!tempo[last12])cnt++; tempo[last12]++; } last12 = last11; last11 = mp[s[indx]]; } else{ if(last21 != 0){ tempo[last21]++; cnt++; } if(last22 != 0){ if(!tempo[last22])cnt++; tempo[last22]++; } last22 = last21; last21 = mp[s[indx]]; } if(!tempo[mp[s[indx]]])cnt++; res = cnt + max(rec(indx + 1, 1, last11, last12, last21, last22), rec(indx + 1, 2, last11, last12, last21, last22)); return table[indx][mine][v[0]][v[1]][v[2]][v[3]] = res; } int main() { cin >> n >> s; mp['M'] = 1; mp['B'] = 2; mp['F'] = 3; for(int i = 0;i < n;++i){ for(int j = 0;j < 2;++j){ for(int l = 0;l < 4;++l){ for(int r = 0;r < 4;++r){ for(int k = 0;k < 4;++k){ for(int z = 0;z < 4;++z){ table[i][j][l][r][k][z] = -1e18; } } } } } } cout << max(rec(0, 1, 0, 0, 0, 0), rec(0, 2, 0, 0, 0, 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...