# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
95244 | easrui | Miners (IOI07_miners) | C++14 | 127 ms | 668 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;
int dec(int a, int b, int c)
{
if(a==0){
if(b==0) return 1;
if(b==c) return 1;
return 2;
}
if(a==b){
if(a==c) return 1;
return 2;
}
if(a==c || b==c) return 2;
return 3;
}
int main()
{
int D[16][16][2], N, val, a1, a2, b1, b2, ans = 0;
string S;
cin >> N >> S;
for(int i=0; i<16; i++){
for(int j=0; j<16; j++){
D[i][j][0] = D[i][j][1] = INT_MIN;
}
}
D[0][0][1] = 0;
for(int i=0; i<N; i++){
if(S[i] == 'M') val = 1;
if(S[i] == 'B') val = 2;
if(S[i] == 'F') val = 3;
for(int j=0; j<16; j++){
for(int k=0; k<16; k++){
a2 = j%4;
a1 = j/4;
b2 = k%4;
b1 = k/4;
D[a2*4+val][k][i%2] = max(D[a2*4+val][k][i%2],D[j][k][(i+1)%2] + dec(a1,a2,val));
D[j][b2*4+val][i%2] = max(D[j][b2*4+val][i%2],D[j][k][(i+1)%2] + dec(b1,b2,val));
}
}
}
for(int i=0; i<16; i++){
for(int j=0; j<16; j++){
ans = max(ans,D[i][j][(N-1)%2]);
}
}
cout << ans;
}
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... |