답안 #371282

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
371282 2021-02-26T11:04:07 Z sam571128 JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
347 ms 5556 KB
#include <bits/stdc++.h>

#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int N = 2e5+5;
int cntj[N], cnto[N], cnti[N];

signed main(){
	fastio
	int n,k;
	cin >> n >> k;
	string s;
	cin >> s;
	s = '$' + s;
	cntj[n+1] = cnto[n+1] = cnti[n+1] = 1e18;
	for(int i = 1;i <= n;i++){
		cntj[i] = cntj[i-1], cnto[i] = cnto[i-1], cnti[i] = cnti[i-1];
		if(s[i]=='J'){
			cntj[i]++;
		}else if(s[i]=='O'){
			cnto[i]++;
		}else if(s[i]=='I'){
			cnti[i]++;
		}
	}
	auto check = [&](int i, int j){
		int idx = lower_bound(cntj+1,cntj+n+1,cntj[i-1]+k)-cntj;
		if(idx >= j) return false;
		idx = lower_bound(cnto+1,cnto+n+1,cnto[idx-1]+k)-cnto;
		if(idx >= j) return false;
		idx = lower_bound(cnti+1,cnti+n+1,cnti[idx-1]+k)-cnti;
		if(idx > j) return false;
		else return true;
	};
	int ans = 1e18;
	for(int i = 1;i <= n;i++){
		int l = i, r = n;
		while(l < r){
			int mid = l+r>>1;
			if(check(i,mid)) r = mid;
			else l = mid+1;
		}
		if(check(i,l)){
			ans = min(l-i+1-k*3,ans);
		}
	}
	cout << (ans==1e18 ? -1 : ans) << "\n";
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:42:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 |    int mid = l+r>>1;
      |              ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 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 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 368 KB Output is correct
8 Correct 1 ms 384 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
14 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 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 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 368 KB Output is correct
8 Correct 1 ms 384 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
14 Correct 1 ms 364 KB Output is correct
15 Correct 3 ms 364 KB Output is correct
16 Correct 3 ms 492 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 3 ms 492 KB Output is correct
20 Correct 3 ms 492 KB Output is correct
21 Correct 2 ms 492 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 2 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
33 Correct 2 ms 492 KB Output is correct
34 Correct 2 ms 492 KB Output is correct
35 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 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 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 368 KB Output is correct
8 Correct 1 ms 384 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
14 Correct 1 ms 364 KB Output is correct
15 Correct 3 ms 364 KB Output is correct
16 Correct 3 ms 492 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 3 ms 492 KB Output is correct
20 Correct 3 ms 492 KB Output is correct
21 Correct 2 ms 492 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 2 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
33 Correct 2 ms 492 KB Output is correct
34 Correct 2 ms 492 KB Output is correct
35 Correct 1 ms 492 KB Output is correct
36 Correct 347 ms 5184 KB Output is correct
37 Correct 295 ms 5556 KB Output is correct
38 Correct 294 ms 5556 KB Output is correct
39 Correct 271 ms 5556 KB Output is correct
40 Correct 192 ms 5556 KB Output is correct
41 Correct 269 ms 5556 KB Output is correct
42 Correct 295 ms 5556 KB Output is correct
43 Correct 96 ms 3692 KB Output is correct
44 Correct 125 ms 4448 KB Output is correct
45 Correct 162 ms 5556 KB Output is correct
46 Correct 164 ms 5556 KB Output is correct
47 Correct 166 ms 5556 KB Output is correct
48 Correct 162 ms 5556 KB Output is correct
49 Correct 114 ms 3700 KB Output is correct
50 Correct 162 ms 5556 KB Output is correct
51 Correct 185 ms 5556 KB Output is correct
52 Correct 77 ms 5308 KB Output is correct
53 Correct 86 ms 5556 KB Output is correct
54 Correct 142 ms 5556 KB Output is correct
55 Correct 99 ms 5556 KB Output is correct
56 Correct 67 ms 5556 KB Output is correct