| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1281646 | cjspd_oly | Miners (IOI07_miners) | C++17 | 32 ms | 648 KiB |
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using vii = vector<pii>;
using vvii = vector<vii>;
using l = long long;
using vl = vector<l>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using pll = pair<l, l>;
using vll = vector<pll>;
using vvll = vector<vll>;
using d = double;
using vd = vector<d>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using ld = long double;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pbb = pair<bool, bool>;
using vbb = vector<pbb>;
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
void setIO(string name = "")
{
ios_base::sync_with_stdio(0);
cin.tie(0);
if (!name.empty())
{
(void)freopen((name + ".in").c_str(), "r", stdin);
(void)freopen((name + ".out").c_str(), "w", stdout);
}
}
const ld pi = 3.14159265358979323846;
const l LINF = 1e18;
const l INF = 1e9;
const l MOD = 1e9 + 7;
// const l MOD = 998244353;
const l MAXN = 2e5 + 5;
int gain(int a, int b, int c)
{
bool used[4] = {0};
if (a)
used[a] = true;
if (b)
used[b] = true;
if (c)
used[c] = true;
return used[1] + used[2] + used[3];
}
int mp(char ch)
{
if (ch == 'M')
return 1;
if (ch == 'F')
return 2;
if (ch == 'B')
return 3;
return 0; // * none
}
int dp[2][4][4][4][4]; // * DP [prev/cur][mine1 last two foods][mine2 last two foods]
void solve()
{
int n;
string s;
cin >> n >> s;
memset(dp, -1, sizeof(dp));
dp[0][0][0][0][0] = 0;
for (int i = 0; i < n; ++i) {
int x = mp(s[i]);
int cur = i & 1, nxt = cur ^ 1; // * alternate indices similar to swap dp[prev] & dp[next]
memset(dp[nxt], -1, sizeof(dp[nxt]));
for (int a = 0; a < 4; ++a)
for (int b = 0; b < 4; ++b)
for (int c = 0; c < 4; ++c)
for (int d = 0; d < 4; ++d) {
if (dp[cur][a][b][c][d] == -1) continue;
int base = dp[cur][a][b][c][d];
int coal1 = gain(x, a, b);
dp[nxt][x][a][c][d] = max(dp[nxt][x][a][c][d], base + coal1);
int coal2 = gain(x, c, d);
dp[nxt][a][b][x][c] = max(dp[nxt][a][b][x][c], base + coal2);
}
}
int ans = 0;
int last = n & 1;
for (int a = 0; a < 4; ++a)
for (int b = 0; b < 4; ++b)
for (int c = 0; c < 4; ++c)
for (int d = 0; d < 4; ++d)
ans = max(ans, dp[last][a][b][c][d]);
cout << ans << '\n';
}
int main()
{
setIO("");
#ifndef ONLINE_JUDGE
// setIO("filename");
#endif
int t = 1;
// cin >> t;
while (t--)
solve();
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... | ||||
