# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
458143 |
2021-08-08T01:39:04 Z |
JovanB |
Miners (IOI07_miners) |
C++17 |
|
251 ms |
604 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int dp[4][4][4][4];
int dpp[4][4][4][4];
int main(){
ios_base::sync_with_stdio(false);
cout.precision(10);
cout<<fixed;
int n;
cin >> n;
string s;
cin >> s;
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++){
dpp[a][b][c][d] = -100000000;
}
}
}
}
dpp[0][0][0][0] = 0;
for(int i=1; i<=n; i++){
int x;
if(s[i-1] == 'M') x = 1;
else if(s[i-1] == 'F') x = 2;
else x = 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[a][b][c][d] = -100000000;
}
}
}
}
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++){
bool bio[4];
for(int j=1; j<=3; j++) bio[j] = 0;
bio[a] = 1;
bio[b] = 1;
bio[x] = 1;
int sum = 0;
for(int j=1; j<=3; j++){
sum += bio[j];
}
dp[b][x][c][d] = max(dp[b][x][c][d], dpp[a][b][c][d] + sum);
for(int j=1; j<=3; j++) bio[j] = 0;
bio[c] = 1;
bio[d] = 1;
bio[x] = 1;
sum = 0;
for(int j=1; j<=3; j++){
sum += bio[j];
}
dp[a][b][d][x] = max(dp[a][b][d][x], dpp[a][b][c][d] + sum);
}
}
}
}
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++){
dpp[a][b][c][d] = dp[a][b][c][d];
}
}
}
}
}
int mx = 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++){
mx = max(mx, dp[a][b][c][d]);
}
}
}
}
cout << mx;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
188 ms |
564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
251 ms |
604 KB |
Output is correct |