Submission #785371

#TimeUsernameProblemLanguageResultExecution timeMemory
785371AnhPhamMiners (IOI07_miners)C++17
100 / 100
107 ms1364 KiB
#include <bits/stdc++.h> using namespace std; #ifdef anhh_local #include "algo/debug.h" #else #define debug(...)42 #endif #define F_OR(v, l, r, s) for (int v = l; s > 0 ? v <= r : v >= r; v += s) #define F_OR1(r) F_OR(i, 0, r - 1, 1) #define F_OR2(v, r) F_OR(v, 0, r - 1, 1) #define F_OR3(v, l, r) F_OR(v, l, r, 1) #define F_OR4(v, l, r, s) F_OR(v, l, r, s) #define GET5(a, b, c, d, e, ...) e #define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1) #define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__) #define int long long #define pb push_back #define sz(__v) (int)(__v).size() #define all(_v) (_v).begin(), (_v).end() const int mod = (int)1e9 + 7; const vector<int> ext[2] { { 0, -(int)1e9, (int)1e9 }, { 0, -(int)1e18, (int)1e18 } }; signed main(); void solve(); signed main() { #ifndef anhh_local #define anhh "" if (fopen(anhh".inp", "r")) assert(freopen(anhh".inp", "r", stdin)), assert(freopen(anhh".out", "w", stdout)); #endif cin.tie(nullptr), cout.tie(nullptr) -> sync_with_stdio(0); int testcases = 1; #define testcase 0 if (testcase) cin >> testcases; FOR(test, testcases) solve(); } const int N = (int)1e6 + 6; int n; string str; int s[N]; int dp[2][4][4][4][4]; int standard(char c) { if (c == 'M') return 1; else if (c == 'F') return 2; else return 3; } int f(int a, int b, int c) { int cnt = 0; cnt += a == 1 || b == 1 || c == 1; cnt += a == 2 || b == 2 || c == 2; cnt += a == 3 || b == 3 || c == 3; return cnt; } void solve() { cin >> n >> str; FOR(n) s[i] = standard(str[i]); FOR(i, (n - 1), 0, -1) FOR(a, 4) FOR(b, 4) FOR(c, 4) FOR(d, 4) dp[i & 1][a][b][c][d] = max(dp[(i + 1) & 1][b][s[i]][c][d] + f(a, b, s[i]), dp[(i + 1) & 1][a][b][d][s[i]] + f(c, d, s[i])); cout << dp[0][0][0][0][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...