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>
typedef long long ll;
#define pb push_back
#define MS(x,y) memset((x),(y),sizeof((x)))
const ll MN = 1000000007;
using namespace std;
int n;
int tip[100001];
int dp[100001][4][4][4][4];
int magic(int a, int b, int c) {
unordered_set<int> brr;
brr.insert(a);
brr.insert(b);
brr.insert(c);
int res = 0;
for (auto it:brr) if (it != 3) res++;
return res;
}
int rek(int pos, int lastL, int plastL, int lastR, int plastR) {
if (dp[pos][lastL][plastL][lastR][plastR] != -1) return dp[pos][lastL][plastL][lastR][plastR];
if (pos >= n) return 0;
int ret = rek(pos+1,tip[pos],lastL,lastR,plastR)+magic(lastL,plastL,tip[pos]);
ret = max(ret,rek(pos+1,lastL,plastR,tip[pos],lastR)+magic(lastR,plastR,tip[pos]));
return dp[pos][lastL][plastL][lastR][plastR] = ret;
}
int main()
{
#if LOCAL_DEBUG
fstream cin("in.txt");
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
string s;
cin>>s;
for (int i = 0; i<n; i++) {
if (s[i] == 'R') tip[i] = 0;
else if (s[i] == 'Y') tip[i] = 1;
else if (s[i] == 'G') tip[i] = 2;
}
MS(dp,-1);
cout<<rek(0,3,3,3,3)<<endl;
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... |