Submission #785441

#TimeUsernameProblemLanguageResultExecution timeMemory
785441AnhPhamMiners (IOI07_miners)C++17
41 / 100
297 ms201692 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)1e5 + 6; int n; string str; int s[N]; int dp[N][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; FOR(i, 1, 3) cnt += a == i || b == i || c == i; return cnt; } void solve() { cin >> n >> str; FOR(n) s[i + 1] = standard(str[i]); dp[1][0][0][0][0] = 1; FOR(i, 1, n) FOR(a, 4) FOR(b, 4) FOR(c, 4) FOR(d, 4) dp[i][a][b][c][d] = max(dp[i - 1][b][s[i]][c][d] + f(a, b, s[i]), dp[i - 1][a][b][d][s[i]] + f(c, d, s[i])); cout << dp[n][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...