Submission #103385

#TimeUsernameProblemLanguageResultExecution timeMemory
103385BertedMiners (IOI07_miners)C++14
100 / 100
226 ms640 KiB
#include <iostream> using namespace std; int n,ar[2][4][4][4][4]={},mx=1;string s; int ts(char a) { if (a=='M') {return 1;} else if (a=='B') {return 2;} else {return 3;} } int hm(int a,int b,int c) { bool mp[4]={};int to=0; if (a!=0&&!mp[a]) {mp[a]=true;to++;} if (b!=0&&!mp[b]) {mp[b]=true;to++;} if (c!=0&&!mp[c]) {mp[c]=true;to++;} return to; } int main() { /* #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif*/ cin>>n>>s; ar[1][0][0][0][ts(s[0])] = 1; ar[1][0][ts(s[0])][0][0] = 1; for (int a=2;a<=n;a++) { for (int b=0;b<4;b++) { for (int c=0;c<4;c++) { for (int d=0;d<4;d++) { for (int e=0;e<4;e++) { if (ar[(a-1)%2][b][c][d][e]>0) { ar[a%2][c][ts(s[a-1])][d][e] = max(ar[a%2][c][ts(s[a-1])][d][e],ar[(a-1)%2][b][c][d][e]+hm(b,c,ts(s[a-1]))); ar[a%2][b][c][e][ts(s[a-1])] = max(ar[a%2][b][c][e][ts(s[a-1])],ar[(a-1)%2][b][c][d][e]+hm(d,e,ts(s[a-1]))); mx=max(mx,ar[a%2][c][ts(s[a-1])][d][e]); mx=max(mx,ar[a%2][b][c][e][ts(s[a-1])]); } } } } } } cout<<mx<<"\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...