# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
71495 | RezwanArefin01 | Miners (IOI07_miners) | C++17 | 95 ms | 1100 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;
typedef long long ll;
typedef pair<int, int> ii;
const int N = 1e5 + 10;
int n; char s[N];
int dp[2][13][13], mp[30];
int m[13] = {00, 01, 02, 03, 11, 12, 13, 21, 22, 23, 31, 32, 33}, rev[100];
int cost[13][4];
int get(int mask, int c) {
set<int> st;
while(mask) {
int x = mask % 10;
if(x) st.insert(x);
mask /= 10;
} st.insert(c);
return st.size();
}
int main(int argc, char const *argv[]) {
mp['M' - 'A'] = 1; mp['B' - 'A'] = 2; mp['F' - 'A'] = 3;
for(int i = 0; i < 13; i++) {
rev[m[i]] = i;
for(int j = 1; j <= 3; j++) {
cost[i][j] = get(m[i], j);
}
}
scanf("%d", &n);
scanf(" %s", s + 1);
for(int i = n; i >= 1; --i) {
int now = i & 1, nxt = now ^ 1;
int c = mp[s[i] - 'A'];
for(int m1 = 0; m1 < 13; ++m1) {
for(int m2 = 0; m2 < 13; ++m2) {
int mask1 = m[m1];
int mask2 = m[m2];
int nmask1 = (mask1 % 10) * 10 + c;
int nmask2 = (mask2 % 10) * 10 + c;
int opt1 = dp[nxt][rev[nmask1]][m2] + cost[m1][c];
int opt2 = dp[nxt][m1][rev[nmask2]] + cost[m2][c];
dp[now][m1][m2] = max(opt1, opt2);
}
}
}
printf("%d\n", dp[1][0][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... |