# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
535030 | __Variatto | Crtanje (COCI20_crtanje) | C++17 | 1 ms | 332 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define ll long long
const int MAX=1e5+10;
int n, dp[MAX][4][4][4][4], t[MAX];
string s;
int rozne(int a, int b, int c){
if(!c&&!b)
return 1;
if(!c){
if(b==a)
return 1;
else
return 2;
}
if(a==b&&b==c)
return 1;
else if(a==b||b==c||c==a)
return 2;
else
return 3;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin>>n>>s;
for(int i=1; i<=n; i++){
if(s[i-1]=='M') t[i]=1;
if(s[i-1]=='B') t[i]=2;
if(s[i-1]=='F') t[i]=3;
}
for(int a=0; a<=3; a++)
for(int b=0; b<=3; b++)
for(int c=0; c<=3; c++)
for(int d=0; d<=3; d++)
dp[0][a][b][c][d]=-1;
dp[0][0][0][0][0]=0;
for(int i=1; i<=n; i++){
for(int a=0; a<=3; a++)
for(int b=0; b<=3; b++)
for(int c=0; c<=3; c++)
for(int d=0; d<=3; d++)
dp[i][a][b][c][d]=-1;
for(int a=0; a<=3; a++){
for(int c=0; c<=3; c++){
for(int d=0; d<=3; d++){
for(int b=0; b<=3; b++){
if(dp[i-1][a][b][c][d]==-1)
continue;
dp[i][t[i]][a][c][d]=max(dp[i][t[i]][a][c][d], dp[i-1][a][b][c][d]+rozne(t[i], a, b));
}
}
}
}
for(int a=0; a<=3; a++){
for(int b=0; b<=3; b++){
for(int d=0; d<=3; d++){
for(int c=0; c<=3; c++){
if(dp[i-1][a][b][c][d]==-1)
continue;
dp[i][a][b][t[i]][c]=max(dp[i][a][b][t[i]][c], dp[i-1][a][b][c][d]+rozne(t[i], c, d));
}
}
}
}
}
int maxi=0;
for(int a=0; a<=3; a++)
for(int b=0; b<=3; b++)
for(int c=0; c<=3; c++)
for(int d=0; d<=3; d++)
maxi=max(maxi, dp[n][a][b][c][d]);
cout<<maxi<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |