이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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,plastL,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] == 'M') tip[i] = 0;
else if (s[i] == 'F') tip[i] = 1;
else if (s[i] == 'B') 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... |