이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int v[maxn], dp[maxn][4][4][4][4];
int n;
int val( char c ){
if( c == 'M' ) return 1;
if( c == 'F' ) return 2;
else return 3;
}
int cost( int x, int y, int z ){
set<int> s;
s.insert(x); s.insert(y); s.insert(z);
s.erase(0);
return s.size();
}
int solve( int i, int a, int b, int c, int d ){
if( i == n + 1 ) return 0;
int& res = dp[i][a][b][c][d];
if( res != 0 ) return res;
return res = max( cost( a, b, v[i] ) + solve( i + 1, v[i], a, c, d ), cost( c, d, v[i] ) + solve( i + 1, a, b, v[i], c ) );
}
int main(){
cin >> n;
for( int i = 1; i <= n; i++ ){
char c; cin >> c;
v[i] = val( c );
}
int resp = solve( 1, 0, 0, 0, 0 );
cout << resp;
}
# | 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... |