# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
989668 | aaaaaarroz | Miners (IOI07_miners) | C++17 | 498 ms | 100696 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;
const int nmax = 1e5 + 1;
int dp[nmax][4][4][4][4];
int main() {
int n;
cin >> n;
string v;
cin >> v;
for(auto &it : v) {
if(it == 'B') {
it = 1;
} else if(it == 'F') {
it = 2;
} else {
it = 3;
}
}
for(int i = 0; i <= n; i++) {
for(int a1 = 0; a1 < 4; a1++) {
for(int a2 = 0; a2 < 4; a2++) {
for(int b1 = 0; b1 < 4; b1++) {
for(int b2 = 0; b2 < 4; b2++) {
dp[i][a1][a2][b1][b2] = -1;
}
}
}
}
}
v = "$" + v;
dp[0][0][0][0][0] = 0;
int maxx = 0;
for(int i = 1; i <= n; i++) {
for(int a1 = 0; a1 < 4; a1++) {
for(int a2 = 0; a2 < 4; a2++) {
for(int b1 = 0; b1 < 4; b1++) {
for(int b2 = 0; b2 < 4; b2++) {
if(dp[i - 1][a1][a2][b1][b2] == -1) {
continue;
}
int ia1 = a1, ia2 = a2, ib1 = b1, ib2 = b2;
if(a1 == 0) {
a1 = v[i];
}
if(a2 == 0) {
a2 = v[i];
}
if(b1 == 0) {
b1 = v[i];
}
if(b2 == 0) {
b2 = v[i];
}
map<int, int> fa;
fa[a1], fa[a2], fa[v[i]];
dp[i][ia2][v[i]][ib1][ib2] = max(dp[i][ia2][v[i]][ib1][ib2], int(dp[i - 1][ia1][ia2][ib1][ib2] + fa.size()));
map<int, int> fb;
fb[b1], fb[b2], fb[v[i]];
dp[i][ia1][ia2][ib2][v[i]] = max(dp[i][ia1][ia2][ib2][v[i]], int(dp[i - 1][ia1][ia2][ib1][ib2] + fb.size()));
maxx = max(maxx, dp[i][ia1][ia2][ib2][v[i]]);
maxx = max(maxx, dp[i][ia2][v[i]][ib1][ib2]);
a1 = ia1;
a2 = ia2;
b1 = ib1;
b2 = ib2;
}
}
}
}
}
cout << maxx;
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... |