Submission #167808

#TimeUsernameProblemLanguageResultExecution timeMemory
167808vioalbertMiners (IOI07_miners)C++14
75 / 100
1576 ms122148 KiB
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define pb push_back #define MEM(a, x) memset(a, x, sizeof a) typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; template<typename T> void dbg(T &x) {cerr << x << endl;} template<typename T> void dbga(T &x, int &n) {for(int i = 0; i < n; i++) {cerr << i << ": "; cerr << x[i] << endl;} } template<typename T> void dbgv(T &x) {bool first = true; cerr << "{"; for(auto i : x) {if(!first) cerr << ","; cerr << i; first = false;} cerr << "}" << endl;} int n; string a; map<int, ll> dp[10][10]; int nxt(int st, int idx) { if(a[idx] == 'M') { if(st == 0 || (st % 3 == 1)) return 1; if(st % 3 == 2) return 4; if(st % 3 == 0) return 7; } else if(a[idx] == 'F') { if(st == 0 || (st % 3 == 1)) return 2; if(st % 3 == 2) return 5; if(st % 3 == 0) return 8; } else { if(st == 0 || (st % 3 == 1)) return 3; if(st % 3 == 2) return 6; if(st % 3 == 0) return 9; } } ll val(int st, int idx) { if(a[idx] == 'M') { if(st == 0 || st == 1) return 1; if(st == 6 || st == 8) return 3; else return 2; } else if(a[idx] == 'F') { if(st == 0 || st == 5) return 1; if(st == 3 || st == 7) return 3; else return 2; } else { if(st == 0 || st == 9) return 1; if(st == 2 || st == 4) return 3; else return 2; } } int solve(int idx, int st1, int st2) { if(idx == n) return 0; if(dp[st1][st2].find(idx) != dp[st1][st2].end()) return dp[st1][st2][idx]; return dp[st1][st2][idx] = max(val(st1, idx) + solve(idx+1, nxt(st1, idx), st2), val(st2, idx) + solve(idx+1, st1, nxt(st2, idx))); } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> a; int ans = solve(0,0,0); cout << ans << endl; return 0; }

Compilation message (stderr)

miners.cpp: In function 'int nxt(int, int)':
miners.cpp:33:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#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...