제출 #534835

#제출 시각아이디문제언어결과실행 시간메모리
534835andecaandeciMiners (IOI07_miners)C++17
100 / 100
817 ms210568 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...