이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define KON using
#define AQUA namespace std;
KON AQUA
#define ll long long
#define int long long
#define pb push_back
#define fi first
#define se second
#define INIT ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x) cout << #x << " => " << x << "\n";
#define sp " "
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const int inf = 0x3f3f3f3f;
const int INFF = 1e18 + 5;
const int INF = 1e10 + 5;
const int MX = 3e5 + 5;
const int MXL = 105;
const int mod = 1e9 + 7;
const double ERROR = 1e-5;
int n, dp[MX][4][4][4][4];
string s;
void solve(){
cin >> n >> s;
memset(dp, -1, sizeof(dp));
dp[0][0][0][0][0] = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j <= 3; j++){
for(int k = 0; k <= 3; k++){
for(int l = 0; l <= 3; l++){
for(int m = 0; m <= 3; m++){
if(dp[i][j][k][l][m] == -1) continue;
int next = (s[i] == 'M' ? 1 : s[i] == 'F' ? 2 : 3);
set <int> s1, s2;
s1.insert(next);
if(j) s1.insert(j);
if(k) s1.insert(k);
dp[i + 1][next][j][l][m] = max(dp[i + 1][next][j][l][m], dp[i][j][k][l][m] + (int) s1.size());
s2.insert(next);
if(l) s2.insert(l);
if(m) s2.insert(m);
dp[i + 1][j][k][next][l] = max(dp[i + 1][j][k][next][l], dp[i][j][k][l][m] + (int) s2.size());
}
}
}
}
}
int ans = 0;
for(int j = 0; j <= 3; j++){
for(int k = 0; k <= 3; k++){
for(int l = 0; l <= 3; l++){
for(int m = 0; m <= 3; m++){
ans = max(ans, dp[n][j][k][l][m]);
}
}
}
}
cout << ans << "\n";
}
int32_t main(){
INIT;
solve();
}
# | 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... |