Submission #217111

# Submission time Handle Problem Language Result Execution time Memory
217111 2020-03-29T01:51:22 Z jamielim JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
43 ms 3192 KB
#include <bits/stdc++.h>
using namespace std;

int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	char str[n+5];
	scanf("%s",str);
	int pre[3][n+1];
	for(int i=0;i<n;i++){
		if(i>0){pre[0][i]=pre[0][i-1];pre[1][i]=pre[1][i-1];pre[2][i]=pre[2][i-1];}else{pre[0][i]=pre[1][i]=pre[2][i]=0;}
		if(str[i]=='O'){
			pre[0][i]=(i==0?1:pre[0][i-1]+1);
		}else if(str[i]=='I'){
			pre[1][i]=(i==0?1:pre[1][i-1]+1);
		}else{
			pre[2][i]=(i==0?1:pre[2][i-1]+1);
		}
	}
	pre[0][n]=1000000010;pre[1][n]=1000000010;pre[2][n]=1000000010;
	int j=0;
	int ans=1000000010;
	for(int i=0;i<n;i++){
		if(str[i]=='J')j++;
		if(j>=k){
			int cur=0;
			int x=lower_bound(pre[2],pre[2]+n+1,j-k+1)-pre[2];
			cur+=i-x+1-k;
			x=lower_bound(pre[0],pre[0]+n+1,k+pre[0][i])-pre[0];
			if(x==n)continue;
			cur+=x-i-k;
			int y=lower_bound(pre[1],pre[1]+n+1,k+pre[1][x])-pre[1];
			if(y==n)continue;
			cur+=y-x-k;
			ans=min(cur,ans);
		}
	}
	if(ans>=1000000010)printf("-1");
	else printf("%d",ans);
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:6:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&k);
  ~~~~~^~~~~~~~~~~~~~
ho_t2.cpp:8:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",str);
  ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 4 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 4 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 512 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 4 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 512 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 35 ms 2816 KB Output is correct
37 Correct 37 ms 3072 KB Output is correct
38 Correct 43 ms 3192 KB Output is correct
39 Correct 34 ms 3072 KB Output is correct
40 Correct 24 ms 3072 KB Output is correct
41 Correct 31 ms 3104 KB Output is correct
42 Correct 36 ms 3072 KB Output is correct
43 Correct 15 ms 2048 KB Output is correct
44 Correct 17 ms 2432 KB Output is correct
45 Correct 22 ms 3072 KB Output is correct
46 Correct 22 ms 3072 KB Output is correct
47 Correct 22 ms 3072 KB Output is correct
48 Correct 22 ms 3072 KB Output is correct
49 Correct 15 ms 2176 KB Output is correct
50 Correct 22 ms 3072 KB Output is correct
51 Correct 22 ms 3072 KB Output is correct
52 Correct 10 ms 2944 KB Output is correct
53 Correct 11 ms 3072 KB Output is correct
54 Correct 24 ms 3072 KB Output is correct
55 Correct 18 ms 3072 KB Output is correct
56 Correct 13 ms 3072 KB Output is correct