이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int INF=1e9+7;
int dp[4][4][4][4], tmp[4][4][4][4], T[3];
int ile(int a, int b, int c) {
T[0]=a;
T[1]=b;
T[2]=c;
if(T[2]<T[1]) swap(T[2], T[1]);
if(T[1]<T[0]) swap(T[0], T[1]);
if(T[2]<T[1]) swap(T[2], T[1]);
int ans=1;
if(T[0]==0) ans=0;
if(T[1]!=T[0]) ++ans;
if(T[2]!=T[1]) ++ans;
return ans;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n;
string s;
cin >> n >> s;
rep(a, 4) rep(b, 4) rep(c, 4) rep(d, 4) dp[a][b][c][d]=-INF;
dp[0][0][0][0]=0;
for(auto i : s) {
rep(a, 4) rep(b, 4) rep(c, 4) rep(d, 4) tmp[a][b][c][d]=-INF;
rep(a, 4) rep(b, 4) rep(c, 4) rep(d, 4) {
int x=1;
if(i=='F') x=2;
else if(i=='B') x=3;
tmp[a][b][d][x]=max(tmp[a][b][d][x], dp[a][b][c][d]+ile(c, d, x));
tmp[b][x][c][d]=max(tmp[b][x][c][d], dp[a][b][c][d]+ile(a, b, x));
}
rep(a, 4) rep(b, 4) rep(c, 4) rep(d, 4) dp[a][b][c][d]=tmp[a][b][c][d];
}
int ans=0;
rep(a, 4) rep(b, 4) rep(c, 4) rep(d, 4) ans=max(ans, dp[a][b][c][d]);
cout << ans << '\n';
}
# | 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... |