#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}] = 1;
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){
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
492 KB |
Output is correct |
2 |
Correct |
7 ms |
1004 KB |
Output is correct |
3 |
Correct |
11 ms |
1388 KB |
Output is correct |
4 |
Correct |
23 ms |
2156 KB |
Output is correct |
5 |
Correct |
35 ms |
3448 KB |
Output is correct |
6 |
Correct |
44 ms |
3468 KB |
Output is correct |
7 |
Correct |
45 ms |
3960 KB |
Output is correct |
8 |
Correct |
42 ms |
3320 KB |
Output is correct |
9 |
Correct |
44 ms |
3576 KB |
Output is correct |
10 |
Correct |
41 ms |
3448 KB |
Output is correct |
11 |
Correct |
43 ms |
5112 KB |
Output is correct |
12 |
Correct |
31 ms |
2172 KB |
Output is correct |
13 |
Correct |
26 ms |
1528 KB |
Output is correct |
14 |
Correct |
38 ms |
6136 KB |
Output is correct |
15 |
Correct |
17 ms |
1144 KB |
Output is correct |