Submission #1297436

#TimeUsernameProblemLanguageResultExecution timeMemory
1297436kantaponzJOIOJI (JOI14_joioji)C++20
95 / 100
46 ms7296 KiB
#include <bits/stdc++.h> using namespace std; int N; string S; int A[200005], B[200005]; int main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> N >> S; map<pair<int,int>,int> mp; for (int i = 1; i <= N; i++) { char x = S[i - 1]; if (x == 'J') { A[i]++; B[i]++; } else if (x == 'I') { A[i]--; } else { B[i]--; } } for (int i = 1; i <= N; i++) { A[i] += A[i - 1]; B[i] += B[i - 1]; if (mp.find({A[i], B[i]}) == mp.end()) mp[{A[i], B[i]}] = i; } int ans = 0; for (int i = 1; i <= N; i++) { if (mp[{A[i], B[i]}] != 0) { ans = max(ans, i - mp[{A[i], B[i]}]); } } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...