답안 #997767

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
997767 2024-06-12T19:35:53 Z mnieplowicz JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
13 ms 2144 KB
#include <bits/stdc++.h>
using namespace std;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n, k;
	cin >> n >> k;
	vector<char> s(n);
	vector<int> J, O, I;
	for(int i = 0; i < n; i++){
		cin >> s[i];
		if(s[i] == 'J') J.push_back(i);
		if(s[i] == 'O') O.push_back(i);
		if(s[i] == 'I') I.push_back(i);
	}
	int res = 1e9;
	for(int i = 0; i < J.size() - k + 1; i++){
		int a = J[i + k - 1];
		int b = lower_bound(O.begin(), O.end(), a) - O.begin();
		if(b + k - 1 >= O.size()) continue;
		int c = lower_bound(I.begin(), I.end(), O[b + k - 1]) - I.begin();
		if(c + k - 1 >= I.size()) continue;
		res = min(res, I[c + k - 1] - J[i] - k * 3 + 1);	
	}
	if(res == 1e9) cout << -1 << '\n';
	else cout << res << '\n';
	return 0;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:19:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |  for(int i = 0; i < J.size() - k + 1; i++){
      |                 ~~^~~~~~~~~~~~~~~~~~
ho_t2.cpp:22:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |   if(b + k - 1 >= O.size()) continue;
      |      ~~~~~~~~~~^~~~~~~~~~~
ho_t2.cpp:24:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |   if(c + k - 1 >= I.size()) continue;
      |      ~~~~~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 452 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 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 0 ms 456 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 424 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 452 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 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 0 ms 456 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 424 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 9 ms 1712 KB Output is correct
37 Correct 9 ms 1944 KB Output is correct
38 Correct 9 ms 1896 KB Output is correct
39 Correct 8 ms 2004 KB Output is correct
40 Correct 7 ms 2012 KB Output is correct
41 Correct 8 ms 1976 KB Output is correct
42 Correct 13 ms 2012 KB Output is correct
43 Correct 5 ms 1448 KB Output is correct
44 Correct 6 ms 1496 KB Output is correct
45 Correct 10 ms 2140 KB Output is correct
46 Correct 11 ms 1924 KB Output is correct
47 Correct 7 ms 2012 KB Output is correct
48 Correct 8 ms 2136 KB Output is correct
49 Correct 7 ms 1496 KB Output is correct
50 Correct 10 ms 1896 KB Output is correct
51 Correct 8 ms 2012 KB Output is correct
52 Correct 5 ms 1664 KB Output is correct
53 Correct 6 ms 1996 KB Output is correct
54 Correct 5 ms 2144 KB Output is correct
55 Correct 7 ms 2144 KB Output is correct
56 Correct 4 ms 2144 KB Output is correct