답안 #205314

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
205314 2020-02-28T14:15:33 Z TadijaSebez JJOOII 2 (JOI20_ho_t2) C++11
100 / 100
31 ms 2936 KB
#include <bits/stdc++.h>
using namespace std;
const int N=200050;
const int inf=1e9+7;
int J[N],O[N],I[N];
char str[N];
int main(){
	int n,k;
	scanf("%i %i",&n,&k);
	scanf("%s",str+1);
	for(int i=1;i<=n;i++){
		J[i]=J[i-1]+(str[i]=='J');
		O[i]=O[i-1]+(str[i]=='O');
		I[i]=I[i-1]+(str[i]=='I');
	}
	int ans=inf;
	for(int i=1;i<=n;i++){
		int top=n,bot=i,mid,pos=n+1;
		while(top>=bot){
			mid=top+bot>>1;
			if(J[mid]-J[i-1]>=k)pos=mid,top=mid-1;
			else bot=mid+1;
		}
		if(pos==n+1)continue;
		int tmp=pos;
		top=n,bot=pos+1,pos=n+1;
		while(top>=bot){
			mid=top+bot>>1;
			if(O[mid]-O[tmp]>=k)pos=mid,top=mid-1;
			else bot=mid+1;
		}
		if(pos==n+1)continue;
		tmp=pos;
		top=n,bot=pos+1,pos=n+1;
		while(top>=bot){
			mid=top+bot>>1;
			if(I[mid]-I[tmp]>=k)pos=mid,top=mid-1;
			else bot=mid+1;
		}
		if(pos==n+1)continue;
		ans=min(ans,pos-i+1-3*k);
	}
	if(ans==inf)printf("-1\n");
	else printf("%i\n",ans);
	return 0;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:20:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    mid=top+bot>>1;
        ~~~^~~~
ho_t2.cpp:28:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    mid=top+bot>>1;
        ~~~^~~~
ho_t2.cpp:36:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    mid=top+bot>>1;
        ~~~^~~~
ho_t2.cpp:9:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&n,&k);
  ~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",str+1);
  ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 380 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 5 ms 380 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 380 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 5 ms 380 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 248 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 380 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 5 ms 380 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 248 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 26 ms 2680 KB Output is correct
37 Correct 28 ms 2808 KB Output is correct
38 Correct 27 ms 2808 KB Output is correct
39 Correct 29 ms 2812 KB Output is correct
40 Correct 24 ms 2808 KB Output is correct
41 Correct 27 ms 2808 KB Output is correct
42 Correct 31 ms 2812 KB Output is correct
43 Correct 14 ms 1912 KB Output is correct
44 Correct 17 ms 2296 KB Output is correct
45 Correct 21 ms 2808 KB Output is correct
46 Correct 22 ms 2936 KB Output is correct
47 Correct 22 ms 2808 KB Output is correct
48 Correct 22 ms 2840 KB Output is correct
49 Correct 15 ms 2040 KB Output is correct
50 Correct 20 ms 2808 KB Output is correct
51 Correct 20 ms 2808 KB Output is correct
52 Correct 12 ms 2808 KB Output is correct
53 Correct 13 ms 2808 KB Output is correct
54 Correct 20 ms 2808 KB Output is correct
55 Correct 14 ms 2808 KB Output is correct
56 Correct 12 ms 2808 KB Output is correct