이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define FF first
#define SS second
#define all(a) a.begin(), a.end()
#define mod (ll)(1000000007)
int count(int a, int b, int c) {
if (a == b && b == c) {
return 1;
}
if (a == b || b == c || a == c) {
return 2;
}
return 3;
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);
int n;
string s;
cin >> n >> s;
vector<vector<vector<vector<int>>>> dp(3, vector<vector<vector<int>>>(3, vector<vector<int>>(3, vector<int>(3))));
for (int i = 0; i < n; i++) {
vector<vector<vector<vector<int>>>> Nxt = dp;
int l = 0;
if (s[i] == 'F') {
l = 1;
}
else if (s[i] == 'B') {
l = 2;
}
for (int a = 0; a < 3; a++) {
for (int b = 0; b < 3; b++) {
for (int c = 0; c < 3; c++) {
for (int d = 0; d < 3; d++) {
Nxt[b][l][c][d] = max(Nxt[b][l][c][d], dp[a][b][c][d] + count(a, b, l));
Nxt[a][b][d][l] = max(Nxt[a][b][d][l], dp[a][b][c][d] + count(c, d, l));
}
}
}
}
dp = Nxt;
}
int ans = 0;
for (int a = 0; a < 3; a++) {
for (int b = 0; b < 3; b++) {
for (int c = 0; c < 3; c++) {
for (int d = 0; d < 3; d++) {
ans = max(ans, dp[a][b][c][d]);
}
}
}
}
cout << ans - 6;
}
# | 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... |