이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h> //:3
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi pair<long double, long double>
#define sz(x) (int)((x).size())
//#define int long long
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const ll inf = 2e9;
const ll mod = 1e9 + 7;
const int N = 1e5 + 11;
const ll INF64 = 3e18 + 1;
const double eps = 1e-14;
const double PI = acos(-1);
//ifstream in(".in");
//ofstream out(".out");
int n, y[N];
string s;
int dp[N][4][4][4][4], reach[N][4][4][4][4];
//dp[i][second last from the first mine][last from the first mine][second last from the second mne][last from the second mine]
int val(int a, int b, int c){
int x = 0;
for(int i = 1; i <= 3; i++){
if(i == a || i == b || i == c)x++;
}
return x;
}
void solve(){
cin >> n >> s;
int ans = 0;
s = '.' + s;
for(int i = 1; i <= n; i++){
y[i] = (s[i] == 'B' ? 1 : (s[i] == 'F' ? 2 : 3));
}
reach[0][0][0][0][0] = 1;
for(int i = 1; i <= n; i++){
int x = y[i];
for(int a = 0; a < 4; a++){
for(int b = 0; b < 4; b++){
for(int c = 0; c < 4; c++){
for(int d = 0; d < 4; d++){
if(!reach[i - 1][a][b][c][d])continue;
reach[i][x][a][c][d] = 1;
reach[i][a][b][x][c] = 1;
dp[i][x][a][c][d] = max(dp[i][x][a][c][d], dp[i - 1][a][b][c][d] + val(x, a, b));
dp[i][a][b][x][c] = max(dp[i][a][b][x][c], dp[i - 1][a][b][c][d] + val(x, c, d));
ans = max(ans, dp[i][a][b][x][c]);
ans = max(ans, dp[i][x][a][c][d]);
}
}
}
}
}
cout << ans << '\n';
}
int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
//cout << setprecision(6) << fixed;
int T = 1;
//cin >> T;
while(T--){
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... |