Submission #156044

#TimeUsernameProblemLanguageResultExecution timeMemory
156044souhhcongJOIOJI (JOI14_joioji)C++14
95 / 100
65 ms7916 KiB
#include <iostream> #include <map> #include <stdio.h> #include <string.h> using namespace std; #define cnt_I first #define cnt_O second.first #define cnt_J second.second typedef pair<int,int> ii; typedef pair<int,ii> iii; const int N = 2e5+5; int n, ans = 0; string s; iii pref[N]; map<iii,int> check; int main() { cin >> n >> s; if (s[0] == 'I') pref[0].cnt_I++; else if (s[0] == 'O') pref[0].cnt_O++; else pref[0].cnt_J++; check[pref[0]] = 1; for (int i = 1; i < n; i++) { pref[i] = pref[i-1]; if (s[i] == 'I') pref[i].cnt_I++; else if (s[i] == 'O') pref[i].cnt_J++; else pref[i].cnt_O++; int tmp = min(pref[i].cnt_I,min(pref[i].cnt_O,pref[i].cnt_J)); pref[i].cnt_I -= tmp; pref[i].cnt_O -= tmp; pref[i].cnt_J -= tmp; if (check[pref[i]]) { ans = max(ans,i+1-check[pref[i]]); } else check[pref[i]] = i+1; } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...