Submission #156037

#TimeUsernameProblemLanguageResultExecution timeMemory
156037shuvi_dolaJOIOJI (JOI14_joioji)C++14
95 / 100
63 ms7944 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; for(int i = 0; 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> v1 = {cntj[i] - cnti[i], cntj[i] - cnto[i]}; if(m[v1] == 0) m[v1] = i; } int ans = 0; for(int i = n - 1; i >= 0; i--) { pair <int, int> v1 = {cntj[i] - cnti[i], cntj[i] - cnto[i]}; int j = m[v1]; 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...