| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 831477 | OrazB | Miners (IOI07_miners) | C++14 | 1575 ms | 1728 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;
#define all(x) (x).begin(), (x).end()
#define ll long long int
#define pii pair <int, int>
#define pb push_back
#define ff first
#define ss second
const int N = 1e5+5;
int nw[26], A[3], vis[N];
pair<int,pii> dp[N][5];
int T(char c){
if (c == 'M') return 0;
if (c == 'B') return 1;
return 2;
}
int main ()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
string s;
cin >> n >> s;
int mx = 0, x = 0, y = 0;
for (int i = 1; i < n; i++){
for (int j = i-1; j >= 0; j--){
int p = T(s[j]);
for (int k = 0; k < 3; k++){
if (dp[j][k].ff == 0) continue;
A[k] = 1;
A[T(s[i])] = 1;
A[p] = 1;
int cnt = (A[0]+A[1]+A[2]);
if (dp[i][p].ff < cnt+dp[j][k].ff){
dp[i][p] = {cnt+dp[j][k].ff, {j, k}};
}
A[0] = A[1] = A[2] = 0;
}
if (dp[i][p].ff < (s[i]!=s[j])+2){
dp[i][p] = {(s[i]!=s[j])+2, {j, -1e9}};
}
if (mx <= dp[i][p].ff){
mx = dp[i][p].ff;
x = i;
y = p;
}
}
}
int ans = 0;
ans += mx;
while(1){
vis[x] = 1;
if (x == 0) break;
int new_x, new_y;
new_x = dp[x][y].ss.ff;
new_y = dp[x][y].ss.ss;
x = new_x;
y = new_y;
}
string str = "";
for (int i = 0; i < n; i++) if (vis[i] == 0) str += s[i];
for (int i = 0; i < str.size(); i++){
for (int j = i; j > max(i-3, -1); j--){
A[T(str[j])] = 1;
}
ans += A[0]+A[1]+A[2];
A[0] = A[1] = A[2] = 0;
}
cout << ans << '\n';
} 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... | ||||
