답안 #205727

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
205727 2020-02-29T15:35:22 Z T0p_ JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
37 ms 2936 KB
#include<bits/stdc++.h>
using namespace std;

int cnt[4][200200];
char str[200200];
unordered_map<char, int> m;

int main()
{
	m['J'] = 1;
	m['O'] = 2;
	m['I'] = 3;
	int n, k, ans = 1e9;
	scanf(" %d %d",&n,&k);
	scanf(" %s",str+1);
	for(int i=1 ; i<=n ; i++)
	{
		cnt[m[str[i]]][i]++;
		for(int j=1 ; j<=3 ; j++)
			cnt[j][i] += cnt[j][i-1];
	}
	for(int i=1 ; i<=n-k-k ; i++)
	{
		if(cnt[1][i] >= k)
		{
			int l = 1, r = i;
			while(l!=r)
			{
				int mid = (l+r+1)>>1;
				if(cnt[1][i] - cnt[1][mid-1] >=k) l = mid;
				else r = mid-1;
			}
			int x = l;
			l = i+1, r = n;
			while(l!=r)
			{
				int mid = (l+r)>>1;
				if(cnt[2][mid] - cnt[2][i] >= k) r = mid;
				else l = mid+1;
			}
			if(cnt[2][l] - cnt[2][i] < k || cnt[3][n] - cnt[3][l] < k) goto out;
			int j = l;
			l = j+1, r = n;
			while(l!=r)
			{
				int mid = (l+r)>>1;
				if(cnt[3][mid] - cnt[3][j] >= k) r = mid;
				else l = mid+1;
			}
			int y = l;
			ans = min(ans, y-x+1-k-k-k);
		}
		out: ;
	}
	printf((ans == 1e9) ? "-1\n" : "%d\n", ans);
	return 0;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:14: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:15: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 376 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 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 504 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 6 ms 376 KB Output is correct
13 Correct 6 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 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 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 504 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 6 ms 376 KB Output is correct
13 Correct 6 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 6 ms 376 KB Output is correct
17 Correct 6 ms 380 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 6 ms 376 KB Output is correct
25 Correct 6 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 6 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 6 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 6 ms 376 KB Output is correct
34 Correct 6 ms 372 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 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 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 504 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 6 ms 376 KB Output is correct
13 Correct 6 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 6 ms 376 KB Output is correct
17 Correct 6 ms 380 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 6 ms 376 KB Output is correct
25 Correct 6 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 6 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 6 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 6 ms 376 KB Output is correct
34 Correct 6 ms 372 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 29 ms 2680 KB Output is correct
37 Correct 30 ms 2808 KB Output is correct
38 Correct 30 ms 2808 KB Output is correct
39 Correct 36 ms 2912 KB Output is correct
40 Correct 23 ms 2936 KB Output is correct
41 Correct 32 ms 2808 KB Output is correct
42 Correct 37 ms 2936 KB Output is correct
43 Correct 14 ms 2040 KB Output is correct
44 Correct 16 ms 2296 KB Output is correct
45 Correct 19 ms 2808 KB Output is correct
46 Correct 19 ms 2812 KB Output is correct
47 Correct 18 ms 2808 KB Output is correct
48 Correct 19 ms 2808 KB Output is correct
49 Correct 14 ms 2040 KB Output is correct
50 Correct 19 ms 2824 KB Output is correct
51 Correct 19 ms 2936 KB Output is correct
52 Correct 11 ms 2808 KB Output is correct
53 Correct 11 ms 2936 KB Output is correct
54 Correct 33 ms 2808 KB Output is correct
55 Correct 18 ms 2808 KB Output is correct
56 Correct 11 ms 2808 KB Output is correct