| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1340467 | kawhiet | Miners (IOI07_miners) | C++20 | 434 ms | 836 KiB |
#include <bits/stdc++.h>
using namespace std;
int dp[4][4][4][4];
int dp_nxt[4][4][4][4];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
string s;
cin >> n >> s;
vector<int> a(n);
for (int i = 0; i < n; i++) {
if (s[i] == 'M') {
a[i] = 1;
} else if (s[i] == 'B') {
a[i] = 2;
} else {
a[i] = 3;
}
}
auto get = [&](int x, int y, int z) {
set<int> s = {x, y, z};
if (*s.begin() == 0) {
s.erase(s.begin());
}
return (int)s.size();
};
dp[0][a[0]][0][0] = 1;
dp[0][0][0][a[0]] = 1;
for (int i = 1; i < n; i++) {
for (int x1 = 0; x1 < 4; x1++) {
for (int y1 = 0; y1 < 4; y1++) {
for (int x2 = 0; x2 < 4; x2++) {
for (int y2 = 0; y2 < 4; y2++) {
dp_nxt[x1][y1][x2][y2] = 0;
}
}
}
}
for (int x1 = 0; x1 < 4; x1++) {
for (int y1 = 0; y1 < 4; y1++) {
for (int x2 = 0; x2 < 4; x2++) {
for (int y2 = 0; y2 < 4; y2++) {
int k = dp[x1][y1][x2][y2];
if (k == 0) continue;
dp_nxt[x1][y1][y2][a[i]] = max(dp_nxt[x1][y1][y2][a[i]], k + get(x2, y2, a[i]));
dp_nxt[y1][a[i]][x2][y2] = max(dp_nxt[y1][a[i]][x2][y2], k + get(x1, y1, a[i]));
}
}
}
}
swap(dp, dp_nxt);
}
int ans = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
for (int x = 0; x < 4; x++) {
for (int y = 0; y < 4; y++) {
ans = max(ans, dp[i][j][x][y]);
}
}
}
}
cout << ans << '\n';
return 0;
}| # | 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... | ||||
