# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
159799 | karma | Miners (IOI07_miners) | C++14 | 137 ms | 100852 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>
#define FileName "test"
#define ll long long
#define pb emplace_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef pair<ll, ll> pii;
const int N = int(1e5) + 5;
int f[N][4][4][4][4];
int cost[4][4][4], n, c;
string s;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if(fopen(FileName".inp", "r")) {
freopen(FileName".inp", "r", stdin);
freopen(FileName".out", "w", stdout);
}
cin >> n >> s;
for(int i = 0; i < 4; ++i) {
for(int j = 0; j < 4; ++j) {
for(int k = 0; k < 4; ++k) {
set<int> s;
s.insert(i), s.insert(j), s.insert(k), s.erase(0);
cost[i][j][k] = int(s.size());
}
}
}
s = ' ' + s;
memset(&f, -1, sizeof f);
f[0][0][0][0][0] = 0;
for(int i = 1; i <= n; ++i) {
if(s[i] == 'B') c = 1;
else if(s[i] == 'M') c = 2;
else if(s[i] == 'F') c = 3;
for(int j = 0; j < 4; ++j) {
for(int k = 0; k < 4; ++k) {
for(int t = 0; t < 4; ++t) {
for(int l = 0; l < 4; ++l) {
if(f[i - 1][j][k][t][l] == -1) continue;
f[i][j][k][l][c] = max(f[i][j][k][l][c], f[i - 1][j][k][t][l] + cost[t][l][c]);
f[i][k][c][t][l] = max(f[i][k][c][t][l], f[i - 1][j][k][t][l] + cost[j][k][c]);
}
}
}
}
}
int res = 0;
for(int i = 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)
res = max(res, f[n][i][j][k][l]);
}
}
}
cout << res;
}
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... |