# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
578072 |
2022-06-16T00:37:29 Z |
Hacv16 |
Miners (IOI07_miners) |
C++17 |
|
2 ms |
1032 KB |
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
typedef long long ll;
const int MAX = 25;
const int INF = 0x3f3f3f3f;
string s;
int n, v[MAX], memo[MAX][5][5][5][5]; //optimize memory
int f(char c){
if(c == 'M') return 1;
else if(c == 'F') return 2;
return 3;
}
int add(int a, int b, int c){ //size of {a, b, c}
int aux = 0;
if(a) aux |= (1 << a);
if(b) aux |= (1 << b);
if(c) aux |= (1 << c);
return __builtin_popcount(aux);
}
int dp(int i, int a1, int a2, int b1, int b2){
if(memo[i][a1][a2][b1][b2] != -1)
return memo[i][a1][a2][b1][b2];
if(i == n + 1) return 0;
int cur = -INF;
cur = max(cur, dp(i + 1, v[i], a1, b1, b2) + add(v[i], a1, a2));
cur = max(cur, dp(i + 1, a1, a2, v[i], b1) + add(v[i], b1, b2));
return memo[i][a1][a2][b1][b2] = cur;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
memset(memo, -1, sizeof(memo));
cin >> n >> s;
for(int i = 0; i < n; i++)
v[i + 1] = f(s[i]);
cout << dp(1, 0, 0, 0, 0) << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
652 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
652 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
1032 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
1032 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |