| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1180449 | LeonaRaging | Miners (IOI07_miners) | C++20 | 647 ms | 111796 KiB |
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 4;
int n, dp[maxn][4][4][4][4];
string s;
int get(char c) {
if (c == 'M') return 1;
if (c == 'F') return 2;
if (c == 'B') return 3;
}
int get(int a, int b, int c) {
vector<int> vec;
vec.push_back(a);
vec.push_back(b);
vec.push_back(c);
sort(vec.begin(), vec.end());
int res = 1;
for (int i = 0; i < 2; i++)
if (vec[i] != vec[i + 1] && vec[i]) res++;
return res;
}
int Solve(int i, int f1, int f2, int s1, int s2) {
if (i == n) return 0;
if (dp[i][f1][f2][s1][s2] != -1) return dp[i][f1][f2][s1][s2];
dp[i][f1][f2][s1][s2] = max(Solve(i + 1, get(s[i]), f1, s1, s2) + get(get(s[i]), f1, f2),
Solve(i + 1, f1, f2, get(s[i]), s1) + get(get(s[i]), s1, s2));
return dp[i][f1][f2][s1][s2];
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(".INP", "r")) {
freopen(".INP", "r", stdin);
freopen(".OUT", "w", stdout);
}
cin >> n >> s;
memset(dp, -1, sizeof dp);
cout << Solve(0, 0, 0, 0, 0);
// cout << dp[5][2][3][3][2];
}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... | ||||
