제출 #76760

#제출 시각아이디문제언어결과실행 시간메모리
76760MohamedAhmed0Miners (IOI07_miners)C++14
100 / 100
300 ms109100 KiB
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5+5 ; int n , ans = 0; string s ; int dp[MAX][4][4][4][4] ; int diff(int a , int b , int c) { int x = 3 , y = (a == 0) + (b == 0) + (c == 0); if(a == b || b == c || c == a) x = 2 ; if(y == 2) x = 1 ; if(y == 1) x--; if(a == b && b == c) x = 1 ; return x; } int solve(int idx , int prev , int prev1 , int prev2 , int prev3) { if(idx == n) return 0 ; int &ret = dp[idx][prev][prev1][prev2][prev3] ; if(ret != -1) return ret ; int choice1 = 0 , choice2 = 0 ; int type ; if(s[idx] == 'B') type = 1 ; else if(s[idx] == 'M') type = 2 ; else type = 3 ; choice1 = solve(idx + 1 , type , prev , prev2 , prev3) + diff(prev , prev1 , type); choice2 = solve(idx + 1 , prev , prev1 , type , prev2) + diff(prev2 , prev3 , type); return (ret = max(choice1 , choice2)); } int main() { memset(dp , -1 , sizeof(dp)); cin>>n ; cin>>s ; cout<<solve(0 , 0 , 0 , 0 , 0)<<"\n"; 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...