Submission #724743

#TimeUsernameProblemLanguageResultExecution timeMemory
724743hyakupMiners (IOI07_miners)C++17
100 / 100
805 ms108792 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int v[maxn], dp[maxn][4][4][4][4]; int n; int val( char c ){ if( c == 'M' ) return 1; if( c == 'F' ) return 2; else return 3; } int cost( int x, int y, int z ){ set<int> s; s.insert(x); s.insert(y); s.insert(z); s.erase(0); return s.size(); } int solve( int i, int a, int b, int c, int d ){ if( i == n + 1 ) return 0; int& res = dp[i][a][b][c][d]; if( res != 0 ) return res; return res = max( cost( a, b, v[i] ) + solve( i + 1, v[i], a, c, d ), cost( c, d, v[i] ) + solve( i + 1, a, b, v[i], c ) ); } int main(){ cin >> n; for( int i = 1; i <= n; i++ ){ char c; cin >> c; v[i] = val( c ); } int resp = solve( 1, 0, 0, 0, 0 ); cout << resp; }
#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...