# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1066891 | KasymK | Miners (IOI07_miners) | C++17 | 73 ms | 1112 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 ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int dp[2][4][4][4][4];
int main(){
int n;
scanf("%d", &n);
int a[n];
string s;
cin >> s;
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;
}
for(int x = n-1; x >= 0; --x)
for(int a1 = 0; a1 <= 3; ++a1)
for(int a2 = 0; a2 <= 3; ++a2)
for(int b1 = 0; b1 <= 3; ++b1)
for(int b2 = 0; b2 <= 3; ++b2){
int o = 0, o1 = 0, o2 = 0;
o = (a1 == 1 or a2 == 1 or a[x] == 1 ? 1 : 0);
o1 = (a1 == 2 or a2 == 2 or a[x] == 2 ? 1 : 0);
o2 = (a1 == 3 or a2 == 3 or a[x] == 3 ? 1 : 0);
int m1 = o+o1+o2;
o = 0, o1 = 0, o2 = 0;
o = (b1 == 1 or b2 == 1 or a[x] == 1 ? 1 : 0);
o1 = (b1 == 2 or b2 == 2 or a[x] == 2 ? 1 : 0);
o2 = (b1 == 3 or b2 == 3 or a[x] == 3 ? 1 : 0);
int m2 = o+o1+o2;
dp[x&1][a1][a2][b1][b2] = max(dp[(x+1)&1][a[x]][a1][b1][b2]+m1,
dp[(x+1)&1][a1][a2][a[x]][b1]+m2);
}
int answer = dp[0][0][0][0][0];
printf("%d\n", answer);
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... |