Submission #366987

# Submission time Handle Problem Language Result Execution time Memory
366987 2021-02-15T22:49:06 Z MilosMilutinovic JOIOJI (JOI14_joioji) C++14
100 / 100
49 ms 6124 KB
#include <bits/stdc++.h>
using namespace std;
const int N=2000050;
int n;
char s[N];
int main(){
	scanf("%i%s",&n,s);
	map<pair<int,int>,int> lst;
	map<char,int> cnt;
	int ans=0;
	if(n<=400){
		for(int i=0;i<n;i++){
			for(int j=i;j<n;j++){
				cnt[s[j]]++;
				if(cnt['J']==cnt['O']&&cnt['O']==cnt['I']){
					ans=max(ans,j-i+1);
				}
			}
			cnt.clear();
		}
		printf("%i",ans);
		return 0;
	}
	for(int i=0;i<n;i++){
		cnt[s[i]]++;
		pair<int,int> curr;
		curr.first=cnt['J']-cnt['O'];
		curr.second=cnt['J']-cnt['I'];
		if(lst[curr]!=0){
			ans=max(ans,i-lst[curr]+1);
		}else lst[curr]=i+1;
	}
	printf("%i",ans);
	return 0;
}

Compilation message

joioji.cpp: In function 'int main()':
joioji.cpp:7:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    7 |  scanf("%i%s",&n,s);
      |  ~~~~~^~~~~~~~~~~~~
# 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 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 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 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 2 ms 364 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 492 KB Output is correct
2 Correct 9 ms 1004 KB Output is correct
3 Correct 13 ms 1516 KB Output is correct
4 Correct 22 ms 2156 KB Output is correct
5 Correct 35 ms 3308 KB Output is correct
6 Correct 49 ms 3436 KB Output is correct
7 Correct 45 ms 3948 KB Output is correct
8 Correct 48 ms 3308 KB Output is correct
9 Correct 44 ms 3712 KB Output is correct
10 Correct 45 ms 3436 KB Output is correct
11 Correct 39 ms 5100 KB Output is correct
12 Correct 33 ms 2284 KB Output is correct
13 Correct 30 ms 1516 KB Output is correct
14 Correct 34 ms 6124 KB Output is correct
15 Correct 23 ms 1132 KB Output is correct