Submission #414635

#TimeUsernameProblemLanguageResultExecution timeMemory
414635AlexRex0Miners (IOI07_miners)C++14
100 / 100
237 ms135316 KiB
#include<bits/stdc++.h> using namespace std; int n; int food[100002]; bool v[100002][4][4][4][4]; int dp[100002][4][4][4][4]; int diff(int a, int b, int c){ int cont = 1; if(a > c){ swap(a, c); } if(a > b){ swap(a, b); } if(b > c){ swap(b, c); } if(a != b){ cont++; } if(c != b){ cont++; } if(a == 0){ cont--; } return cont; } int coal(int i, int x1, int x2, int y1, int y2){ if(i == n + 1) return 0; if(!v[i][x1][x2][y1][y2]){ v[i][x1][x2][y1][y2] = true; int aux = max(coal(i + 1, food[i], x1, y1, y2) + diff(food[i], x1, x2), coal(i + 1, x1, x2, food[i], y1) + diff(food[i], y1, y2)); dp[i][x1][x2][y1][y2] = aux; } return dp[i][x1][x2][y1][y2]; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i = 1; i <= n; ++i){ char asd; cin >> asd; if(asd == 'F'){ food[i] = 1; }else{ if(asd == 'M'){ food[i] = 2; }else{ food[i] = 3; } } } cout << coal(1, 0, 0, 0, 0); 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...