답안 #903228

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
903228 2024-01-11T06:26:24 Z yellowtoad JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
22 ms 2136 KB
#include <iostream>
#include <vector>
using namespace std;

int n, k, l, r, mid, minn = 1e9, pos;
char c[200010];
vector<int> v[200];

int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> c[i];
		v[c[i]].push_back(i);
	}
	for (int i = 1; i <= n; i++) {
		if (c[i] == 'J') {
			l = 0; r = (int)v['J'].size()-1;
			while (l <= r) {
				mid = (l+r)/2;
				if (v['J'][mid] < i) l = mid+1;
				else r = mid-1;
			}
			l += k-1;
			if (l >= v['J'].size()) continue;
			pos = v['J'][l];
			l = 0; r = (int)v['O'].size()-1;
			while (l <= r) {
				mid = (l+r)/2;
				if (v['O'][mid] < pos) l = mid+1;
				else r = mid-1;
			}
			l += k-1;
			if (l >= v['O'].size()) continue;
			pos = v['O'][l];
			l = 0; r = (int)v['I'].size()-1;
			while (l <= r) {
				mid = (l+r)/2;
				if (v['I'][mid] < pos) l = mid+1;
				else r = mid-1;
			}
			l += k-1;
			if (l >= v['I'].size()) continue;
			pos = v['I'][l];
			minn = min(minn,pos-i+1-k*3);
		}
	}
	if (minn == 1e9) cout << -1 << endl;
	else cout << minn << endl;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:13:8: warning: array subscript has type 'char' [-Wchar-subscripts]
   13 |   v[c[i]].push_back(i);
      |     ~~~^
ho_t2.cpp:24:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |    if (l >= v['J'].size()) continue;
      |        ~~^~~~~~~~~~~~~~~~
ho_t2.cpp:33:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |    if (l >= v['O'].size()) continue;
      |        ~~^~~~~~~~~~~~~~~~
ho_t2.cpp:42:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |    if (l >= v['I'].size()) continue;
      |        ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 0 ms 432 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 352 KB Output is correct
6 Correct 0 ms 352 KB Output is correct
7 Correct 1 ms 352 KB Output is correct
8 Correct 1 ms 500 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 356 KB Output is correct
13 Correct 0 ms 444 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 0 ms 432 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 352 KB Output is correct
6 Correct 0 ms 352 KB Output is correct
7 Correct 1 ms 352 KB Output is correct
8 Correct 1 ms 500 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 356 KB Output is correct
13 Correct 0 ms 444 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 700 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 504 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 356 KB Output is correct
30 Correct 0 ms 356 KB Output is correct
31 Correct 1 ms 356 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 356 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 0 ms 432 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 352 KB Output is correct
6 Correct 0 ms 352 KB Output is correct
7 Correct 1 ms 352 KB Output is correct
8 Correct 1 ms 500 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 356 KB Output is correct
13 Correct 0 ms 444 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 700 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 504 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 356 KB Output is correct
30 Correct 0 ms 356 KB Output is correct
31 Correct 1 ms 356 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 356 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 19 ms 1492 KB Output is correct
37 Correct 21 ms 1952 KB Output is correct
38 Correct 20 ms 2100 KB Output is correct
39 Correct 20 ms 1976 KB Output is correct
40 Correct 22 ms 1868 KB Output is correct
41 Correct 22 ms 2008 KB Output is correct
42 Correct 21 ms 2008 KB Output is correct
43 Correct 10 ms 1372 KB Output is correct
44 Correct 17 ms 1508 KB Output is correct
45 Correct 18 ms 1940 KB Output is correct
46 Correct 17 ms 2008 KB Output is correct
47 Correct 17 ms 1860 KB Output is correct
48 Correct 16 ms 2132 KB Output is correct
49 Correct 11 ms 1312 KB Output is correct
50 Correct 16 ms 2008 KB Output is correct
51 Correct 17 ms 2008 KB Output is correct
52 Correct 12 ms 1492 KB Output is correct
53 Correct 13 ms 1804 KB Output is correct
54 Correct 16 ms 2136 KB Output is correct
55 Correct 14 ms 2088 KB Output is correct
56 Correct 16 ms 2128 KB Output is correct