Submission #156041

#TimeUsernameProblemLanguageResultExecution timeMemory
156041shuvi_dolaJOIOJI (JOI14_joioji)C++14
100 / 100
64 ms8044 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int cnti[N], cntj[N], cnto[N]; map <pair <int, int>, int> m; string s; int n; int main() { cin >> n; cin >> s; s = "1" + s; pair <int, int> v = {0, 0}; m[v] = 0; for(int i = 1; i <= n; i++) { cnti[i] = cnti[i - 1] + (s[i] == 'I'); cntj[i] = cntj[i - 1] + (s[i] == 'J'); cnto[i] = cnto[i - 1] + (s[i] == 'O'); pair <int, int> v = {cntj[i] - cnti[i], cntj[i] - cnto[i]}; if(m.find(v) == m.end()) m[v] = i; } int ans = 0; for(int i = n; i >= 1; i--) { pair <int, int> v = {cntj[i] - cnti[i], cntj[i] - cnto[i]}; int j = m[v]; ans = max(ans, i - j); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...