Submission #642601

#TimeUsernameProblemLanguageResultExecution timeMemory
642601someoneJOIOJI (JOI14_joioji)C++14
100 / 100
38 ms7272 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 2e5 + 42, INF = 1e18 + 42; int n, nb[3], val[N]; map<pair<int, int>, int> first; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for(int i = 0; i < n; i++) { char c; cin >> c; if(c == 'O') val[i] = 1; else if(c == 'I') val[i] = 2; } int maxi = 0; first[{0, 0}] = -1; for(int i = 0; i < n; i++) { nb[val[i]]++; if(first.find({nb[1] - nb[0], nb[2] - nb[0]}) == first.end()) { first[{nb[1] - nb[0], nb[2] - nb[0]}] = i; } else { maxi = max(maxi, i - first[{nb[1] - nb[0], nb[2] - nb[0]}]); } } cout << maxi; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...