Submission #1249272

#TimeUsernameProblemLanguageResultExecution timeMemory
1249272tvgkJOIOJI (JOI14_joioji)C++20
100 / 100
29 ms6196 KiB
#include<bits/stdc++.h> using namespace std; #define task "a" #define se second #define fi first #define ll long long #define ii pair<int, int> const long mxN = 2e5 + 7; char chr[4] = {'J', 'O', 'I'}; int cnt[4]; map<ii, int> m; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //freopen(task".INP", "r", stdin); //freopen(task".OUT", "w", stdout); int n; string s; cin >> n; cin >> s; s = '0' + s; m[{0, 0}] = 0; int ans = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j < 3; j++) cnt[j] += (chr[j] == s[i]); ii tmp = {cnt[0] - cnt[1], cnt[0] - cnt[2]}; if (m.count(tmp)) ans = max(ans, i - m[tmp]); else m[tmp] = i; } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...