Submission #156038

#TimeUsernameProblemLanguageResultExecution timeMemory
156038souhhcongJOIOJI (JOI14_joioji)C++14
95 / 100
57 ms8584 KiB
#include <iostream> #include <map> #include <stdio.h> #include <string.h> using namespace std; const int N = 2e5+5; const long long mpI = 1e13+7, mpO = 1e13+9, mpJ = -(mpI+mpO); int n, ans = 0; string s; long long pref[N], a[N]; map<long long,int> check; int main() { cin >> n >> s; for (int i = 0; i < n; i++) { if (s[i] == 'I') a[i+1] = mpI; else if (s[i] == 'O') a[i+1] = mpO; else a[i+1] = mpJ; } for (int i = 1; i <= n; i++) { pref[i] = pref[i-1] + a[i]; if (check[pref[i]]) { ans = max(ans,i-check[pref[i]]); } else check[pref[i]] = i; } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...