# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
890779 | Sir_Ahmed_Imran | Miners (IOI07_miners) | C++17 | 1557 ms | 100444 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.
///~~~LOTA~~~///
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define ff first
#define ss second
#define ll long long
#define append push_back
#define all(x) (x).begin(),(x).end()
#define N 100001
int dp[N][4][4][4][4];
int c(int n,int m,int o){
set<int> s;
if(n) s.insert(n);
if(m) s.insert(m);
if(o) s.insert(o);
return s.size();
}
map<char,int> x;
void solve(){
char s;
int n,m,o,p,q,r;
cin>>n;
x['M']=1;
x['F']=2;
x['B']=3;
for(int i=0;i<=n;i++)
for(int j=0;j<4;j++)
for(int k=0;k<4;k++)
for(int l=0;l<4;l++)
for(int t=0;t<4;t++)
dp[i][j][k][l][t]=-1e9;
dp[0][0][0][0][0]=0;
for(int i=0;i<n;i++){
cin>>s;
m=x[s];
for(int j=0;j<4;j++){
for(int k=0;k<4;k++){
for(int l=0;l<4;l++){
for(int t=0;t<4;t++){
dp[i+1][k][m][l][t]=max(dp[i+1][k][m][l][t]
,dp[i][j][k][l][t]+c(j,k,m));
dp[i+1][j][k][t][m]=max(dp[i+1][j][k][t][m]
,dp[i][j][k][l][t]+c(l,t,m));
}
}
}
}
}
for(int i=o=0;i<4;i++)
for(int j=0;j<4;j++)
for(int k=0;k<4;k++)
for(int l=0;l<4;l++)
o=max(o,dp[n][i][j][k][l]);
cout<<o;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |