제출 #643593

#제출 시각아이디문제언어결과실행 시간메모리
643593Cyber_WolfMiners (IOI07_miners)C++14
100 / 100
1052 ms142332 KiB
// Problem: P4 - Miners // Contest: DMOJ - IOI '07 // URL: https://dmoj.ca/problem/ioi07p4 // Memory Limit: 16 MB // Time Limit: 750 ms // // Powered by CP Editor (https://cpeditor.org) #include <bits/stdc++.h> using namespace std; #define lg int #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); const lg N = 1e5+5; lg dp[N][256]; lg n; string s; vector<lg> v(N); lg solve(lg idx, lg bit) { if(idx == n) { return 0; } auto &ret = dp[idx][bit]; if(~ret) return ret; lg x = ((bit/64)&3), y = ((bit/16)&3), a = ((bit/4)&3), b = (bit&3); set<lg> se1; if(v[idx] != 3) se1.insert(v[idx]); if(x != 3) se1.insert(x); if(y != 3) se1.insert(y); set<lg> se2; if(v[idx] != 3) se2.insert(v[idx]); if(a != 3) se2.insert(a); if(b != 3) se2.insert(b); lg ch1 = solve(idx+1, v[idx]*64+x*16+a*4+b)+se1.size(); lg ch2 = solve(idx+1, x*64+y*16+v[idx]*4+a)+se2.size(); return ret = max(ch1, ch2); } int main() { fastio; cin >> n >> s; for(int i = 0; i < n; i++) { if(s[i] == 'M') v[i] = 1; if(s[i] == 'B') v[i] = 2; for(int j = 0; j < 256; j++) { dp[i][j] = -1; } } cout << solve(0, 3*64+3*16+3*4+3) << '\n'; return 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...