이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define REP(v, i, j) for (int v = i; v != j; v++)
#define FORI(v) for (auto i : v)
#define FORJ(v) for (auto j : v)
#define OUT(v, a) FORI(v) cout << i << a;
#define OUTS(v, a, b) cout << v.size() << a; OUT(v, b)
#define in(a, n) REP(i, 0, n) cin >> a[i];
#define SORT(v) sort(begin(v), end(v))
#define REV(v) reverse(begin(v), end(v))
#define pb push_back
#define fi first
#define se second
#define detachIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<pii, pii> piiii;
int memo[4][4][4][4][200000];
int arr[200000];
int n;
int num_uniq(int a1, int a2, int a3)
{
set<int> st;
st.insert(a1);
st.insert(a2);
st.insert(a3);
return st.size() - st.count(3);
}
int dp(int a1, int a2, int b1, int b2, int idx)
{
if (idx == n)
return 0;
int &ans = memo[a1][a2][b1][b2][idx];
if (ans != -1)
return ans;
return ans = max(dp(a2, arr[idx], b1, b2, idx + 1) + num_uniq(a1, a2, arr[idx]),
dp(a1, a2, b2, arr[idx], idx + 1) + num_uniq(b1, b2, arr[idx]));
}
int main()
{
detachIO;
memset(memo, -1, sizeof memo);
cin >> n;
REP(i, 0, n)
{
char c;
cin >> c;
if (c == 'M')
arr[i] = 0;
if (c == 'F')
arr[i] = 1;
if (c == 'B')
arr[i] = 2;
}
cout << dp(3, 3, 3, 3, 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... |