Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef pair < int , int > Pi;
- int main()
- {
- map < Pi, int > mp;
- int N;
- Pi sa = Pi(0, 0);
- string S;
- cin >> N >> S;
- mp[sa] = -1;
- int maxv = 0;
- for(int i = 0; i < N; i++) {
- if(S[i] == 'J') {
- sa.first--, sa.second--;
- }
- if(S[i] == 'O') {
- sa.first++;
- }
- if(S[i] == 'I') {
- sa.second++;
- }
- if(mp.find(sa) == mp.end()) {
- mp[sa] = i;
- } else {
- maxv = max(maxv, i - mp[sa]);
- }
- }
- cout << maxv << endl;
- return (0);
- }
Add Comment
Please, Sign In to add comment