# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
890895 | Sir_Ahmed_Imran | Miners (IOI07_miners) | C++17 | 1602 ms | 704 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 pii pair<int,int>
#define all(x) (x).begin(),(x).end()
int dp[2][4][4][4][4];
set<int> x;
inline int c(int& n,int& m,int& o){
if(n) x.insert(n);
if(m) x.insert(m);
if(o) x.insert(o);
int z=x.size();
x.clear();
return z;
}
void solve(){
char s;
int n,m,o,p,q,r;
cin>>n;
map<pair<pii,pii>,bool> u,v;
dp[0][0][0][0][0]=0;
v[{{0,0},{0,0}}]=1;
for(int i=0;i<n;i++){
cin>>s;
if(s=='M') m=1;
if(s=='F') m=2;
if(s=='B') m=3;
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++){
if(!v[{{j,k},{l,t}}]) continue;
if(!u[{{k,m},{l,t}}]){
dp[(i+1)%2][k][m][l][t]=0;
u[{{k,m},{l,t}}]=1;
}
dp[(i+1)%2][k][m][l][t]=max(dp[(i+1)%2][k][m][l][t]
,dp[i%2][j][k][l][t]+c(j,k,m));
if(!u[{{j,k},{t,m}}]){
dp[(i+1)%2][j][k][t][m]=0;
u[{{j,k},{t,m}}]=1;
}
dp[(i+1)%2][j][k][t][m]=max(dp[(i+1)%2][j][k][t][m]
,dp[i%2][j][k][l][t]+c(l,t,m));
}
}
}
}
swap(v,u);
u.clear();
}
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%2][i][j][k][l]);
cout<<o;
}
int main(){
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... |