#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
void solve(){
int n, j = 0, ii = 0, ans = 0, o = 0;
cin >> n;
string s;
cin >> s;
map<pair<int, int>, int> mp;
mp[{0, 0}] = 0;
for(int i = 0; i < s.size(); ++i){
if(s[i] == 'J') ++j;
if(s[i] == 'O') ++o;
if(s[i] == 'I') ++ii;
if(mp.find({j - o, j - ii}) == mp.end())
mp[{j - o, j - ii}] = i + 1;
else
ans = max(ans, i + 1 - mp[{j - o, j - ii}]);
}
cout << ans << '\n';
}
int main(){
fast;
int t = 1;
// cin >> t;
while(t--)
solve();
return 0;
}
Compilation message
joioji.cpp: In function 'void solve()':
joioji.cpp:16:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | for(int i = 0; i < s.size(); ++i){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
492 KB |
Output is correct |
2 |
Correct |
9 ms |
1008 KB |
Output is correct |
3 |
Correct |
12 ms |
1388 KB |
Output is correct |
4 |
Correct |
22 ms |
2176 KB |
Output is correct |
5 |
Correct |
35 ms |
3320 KB |
Output is correct |
6 |
Correct |
41 ms |
3448 KB |
Output is correct |
7 |
Correct |
44 ms |
3960 KB |
Output is correct |
8 |
Correct |
42 ms |
3320 KB |
Output is correct |
9 |
Correct |
42 ms |
3576 KB |
Output is correct |
10 |
Correct |
41 ms |
3448 KB |
Output is correct |
11 |
Correct |
35 ms |
5240 KB |
Output is correct |
12 |
Correct |
30 ms |
2168 KB |
Output is correct |
13 |
Correct |
26 ms |
1528 KB |
Output is correct |
14 |
Correct |
29 ms |
6136 KB |
Output is correct |
15 |
Correct |
17 ms |
1144 KB |
Output is correct |