답안 #208437

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
208437 2020-03-11T08:05:49 Z cstuart JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
19 ms 2924 KB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007ll
#define EPS 1e-9

typedef long long         ll;
typedef long double       ld;
typedef pair <ll,ll>      pl;
typedef tuple <ll,ll,ll>  tl;

ll N, K, B;
vector <ll> VJ, VO, VI;
vector <ll>::iterator VJS, VJE, VOS, VOE, VIS, VIE;

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin >> N >> K;
	for (ll i = 1; i <= N; i++) {
		char ch;
		cin >> ch;
		if (ch == 'J') VJ.push_back(i);
		else if (ch == 'O') VO.push_back(i);
		else VI.push_back(i);
	}
	
	B = 1000000;
	
	for (ll i = 0; i < (ll)VJ.size(); i++) {
		VJS = VJ.begin() + i;
		if (VJ.end() - VJS <= K - 1) continue;
		VJE = VJS + K - 1;
		VOS = upper_bound(VO.begin(), VO.end(), *VJE);
		if (VO.end() - VOS <= K - 1) continue;
		VOE = VOS + K - 1;
		VIS = upper_bound(VI.begin(), VI.end(), *VOE);
		if (VI.end() - VIS <= K - 1) continue;
		VIE = VIS + K - 1;
		ll C = N - (*VJS - 1) - (N - *VIE) - (3 * K);
		B = min(B, C);
	}
	
	if (B == 1000000) cout << -1;
	else cout << B;
		
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 6 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 376 KB Output is correct
7 Correct 4 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 280 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 4 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 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 6 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 376 KB Output is correct
7 Correct 4 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 280 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 4 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 316 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 376 KB Output is correct
34 Correct 5 ms 252 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 6 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 376 KB Output is correct
7 Correct 4 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 280 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 4 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 316 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 376 KB Output is correct
34 Correct 5 ms 252 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 17 ms 2148 KB Output is correct
37 Correct 19 ms 2652 KB Output is correct
38 Correct 19 ms 2628 KB Output is correct
39 Correct 19 ms 2664 KB Output is correct
40 Correct 16 ms 2660 KB Output is correct
41 Correct 17 ms 2656 KB Output is correct
42 Correct 18 ms 2660 KB Output is correct
43 Correct 12 ms 1772 KB Output is correct
44 Correct 12 ms 1732 KB Output is correct
45 Correct 15 ms 2660 KB Output is correct
46 Correct 16 ms 2596 KB Output is correct
47 Correct 15 ms 2664 KB Output is correct
48 Correct 16 ms 2660 KB Output is correct
49 Correct 12 ms 1520 KB Output is correct
50 Correct 16 ms 2652 KB Output is correct
51 Correct 15 ms 2660 KB Output is correct
52 Correct 11 ms 2020 KB Output is correct
53 Correct 13 ms 2532 KB Output is correct
54 Correct 15 ms 2924 KB Output is correct
55 Correct 11 ms 2924 KB Output is correct
56 Correct 10 ms 2924 KB Output is correct