Guest User

Untitled

a guest
Jan 23rd, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef pair < int , int > Pi;
  4. int main()
  5. {
  6. map < Pi, int > mp;
  7. int N;
  8. Pi sa = Pi(0, 0);
  9. string S;
  10. cin >> N >> S;
  11. mp[sa] = -1;
  12. int maxv = 0;
  13. for(int i = 0; i < N; i++) {
  14. if(S[i] == 'J') {
  15. sa.first--, sa.second--;
  16. }
  17. if(S[i] == 'O') {
  18. sa.first++;
  19. }
  20. if(S[i] == 'I') {
  21. sa.second++;
  22. }
  23. if(mp.find(sa) == mp.end()) {
  24. mp[sa] = i;
  25. } else {
  26. maxv = max(maxv, i - mp[sa]);
  27. }
  28. }
  29. cout << maxv << endl;
  30. return (0);
  31. }
Add Comment
Please, Sign In to add comment