이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n, f[N][16][16], a[N];
pair<int, int> nxt[16][4];
void maximize(int &x, int y){
x=max(x, y);
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i=1; i<=n; ++i){
char c; cin >> c;
a[i]=string("?MFB").find(c);
}
for (int i=0; i<16; ++i) for (int j=1; j<4; ++j){
set<int> st;
st.insert(i%4); st.insert(i/4); st.insert(j);
st.erase(0);
nxt[i][j]={st.size(), (i%4)*4+j};
}
memset(f, -1, sizeof f);
f[0][0][0]=0;
for (int i=0; i<n; ++i){
for (int j=0; j<16; ++j) for (int k=0; k<16; ++k) if (f[i][j][k]!=-1){
maximize(f[i+1][nxt[j][a[i+1]].second][k], f[i][j][k]+nxt[j][a[i+1]].first);
maximize(f[i+1][j][nxt[k][a[i+1]].second], f[i][j][k]+nxt[k][a[i+1]].first);
}
}
int ans=-1;
for (int i=0; i<16; ++i) for (int j=0; j<16; ++j) ans=max(ans, f[n][i][j]);
cout << ans << '\n';
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... |