Submission #156039

#TimeUsernameProblemLanguageResultExecution timeMemory
156039shuvi_dolaJOIOJI (JOI14_joioji)C++14
95 / 100
64 ms7916 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; 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[v] == 0) 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...