이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
typedef long long ll;
const int MAX = 110000;
const int INF = 0x3f3f3f3f;
string s;
int n, v[MAX], memo[MAX][4][4][4][4]; //optimize memory
int add(int a, int b, int c){ //size of {a, b, c}
int aux = 0;
if(a) aux |= (1 << a);
if(b) aux |= (1 << b);
if(c) aux |= (1 << c);
return __builtin_popcount(aux);
}
int dp(int i, int a1, int a2, int b1, int b2){
if(i == n) return 0;
if(memo[i][a1][a2][b1][b2] != -1)
return memo[i][a1][a2][b1][b2];
int cur = -INF;
cur = max(cur, dp(i + 1, v[i], a1, b1, b2) + add(v[i], a1, a2));
cur = max(cur, dp(i + 1, a1, a2, v[i], b1) + add(v[i], b1, b2));
return memo[i][a1][a2][b1][b2] = cur;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
memset(memo, -1, sizeof(memo));
cin >> n >> s;
for(int i = 0; i < n; i++){
if(s[i] == 'M') v[i] = 1;
else if(s[i] == 'F') v[i] = 2;
else v[i] = 3;
}
cout << dp(0, 0, 0, 0, 0) << '\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... |