이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=a; i<=b; ++i)
#define gc getchar_unlocked
#define V vector
int n, w;
int daj[4][4][4];
int main() {
FOR(a, 0, 3) FOR(b, 0, 3) FOR(c, 0, 3) {
V<int> all = {a, b, c};
stable_sort(all.begin(), all.end());
FOR(i, 0, 2) {
if(all[i]==0 || (i>=1&&all[i]==all[i-1])) continue;
daj[a][b][c]++;
}
}
V<V<int>> stary(16, V<int>(16, -1e9));
stary[0][0]=0;
cin>>n;
gc();
FOR(i, 0, n-1) {
char c = gc();
int a=1;
if(c=='M') a=2;
if(c=='F') a=3;
V<V<int>> nowy(16, V<int>(16, -1e9));
nowy[0][0]=0;
FOR(s1, 0, 15) FOR(s2, 0, 15) {
nowy[(s1%4)*4+a][s2]=max(nowy[(s1%4)*4+a][s2], stary[(s1/4*4)+(s1%4)][s2]+daj[s1/4][s1%4][a]);
nowy[s1][(s2%4)*4+a]=max(nowy[s1][(s2%4)*4+a], stary[s1][(s2/4*4)+(s2%4)]+daj[s2/4][s2%4][a]);
}
swap(stary, nowy);
}
int w=0;
FOR(a, 0, 15) FOR(b, 0, 15) w=max(w, stary[a][b]);
cout << w << '\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... |