이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
#define sz(x) (int)(x.size())
using namespace std;
int n, k, m;
string seq;
vector<vector<vector<vector<vector<int>>>>> memo;
int dp(int empl, int prec11, int prec12, int prec21, int prec22) {
if (empl>=n) return 0;
if (memo[empl][prec11][prec12][prec21][prec22]!=-1) {
return memo[empl][prec11][prec12][prec21][prec22];
}
int vaut=seq[empl];
int s1=dp(empl+1, vaut, prec11, prec21, prec22);
int s2=dp(empl+1, prec11, prec12, vaut, prec21);
set<int> f1, f2;
f1.insert(vaut), f2.insert(vaut);
if (prec11!=0) f1.insert(prec11);
if (prec12!=0) f1.insert(prec12);
if (prec21!=0) f2.insert(prec21);
if (prec22!=0) f2.insert(prec22);
s1+=f1.size();
s2+=f2.size();
return memo[empl][prec11][prec12][prec21][prec22]=max(s1, s2);
}
void solve() {
cin >> n;
cin >> seq;
memo.clear();
memo.resize(n, vector<vector<vector<vector<int>>>>(4,
vector<vector<vector<int>>> (4, vector<vector<int>> (4, vector<int>(4, -1)))));
for (auto &u: seq) {
if (u=='M') u=1;
else if (u=='F') u=2;
else u=3;
}
cout << dp(0, 0, 0, 0, 0) << endl;
return;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int tt=1;// cin >> tt;
while(tt--) solve();
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... |