Submission #849511

#TimeUsernameProblemLanguageResultExecution timeMemory
849511myst6JOIOJI (JOI14_joioji)C++14
100 / 100
25 ms5352 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); } for (const pair<int,vector<int>> &p : runs) { const vector<int> &v = p.second; map<int,int> fi; for (int i : v) { if (fi.count(OI[i])) { ans = max(ans, i - fi[OI[i]]); } 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...