Submission #849510

#TimeUsernameProblemLanguageResultExecution timeMemory
849510myst6JOIOJI (JOI14_joioji)C++14
0 / 100
1 ms600 KiB
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; string s; cin >> s; // one table of J-O // one table of O-I int ans = 0; vector<int> JO(N+1), OI(N+1); int j = 0, o = 0, i = 0, idx = 0; for (char c : s) { if (c == 'J') j++; if (c == 'O') o++; if (c == 'I') i++; idx++; JO[idx] = j-o; OI[idx] = o-i; } map<int,vector<int>> runs; for (int i=0; i<=N; i++) { runs[JO[i]].push_back(i); } map<int,int> fi; for (const pair<int,vector<int>> &p : runs) { const vector<int> &v = p.second; for (int i : v) { if (fi.count(OI[i])) { ans = max(ans, i - fi[OI[i]] - 1); } else { fi[OI[i]] = i; } } } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...