답안 #716202

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
716202 2023-03-29T08:40:02 Z YeoBL JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
11 ms 3032 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
int cn(char ch){
	if (ch == 'J') return 0;
	else if (ch == 'O') return 1;
	else return 2;
}
int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, k, ans = 1e9, st, cur; cin >> n >> k;
	string s; cin >> s;
	vector <int> pos[3];
	for (int i = 0; i < s.size(); i++){
		pos[cn(s[i])].pb(i);
	}
	for (int i = 0; i + k - 1 < pos[0].size(); i++){
		cur = pos[0][i + k - 1];
		int tmp = (upper_bound(pos[1].begin(), pos[1].end(), cur) - pos[1].begin()) + k - 1;
		if (tmp >= pos[1].size()) continue;
		else cur = pos[1][tmp];
		tmp = (upper_bound(pos[2].begin(), pos[2].end(), cur) - pos[2].begin()) + k - 1;
		if (tmp >= pos[2].size()) continue;
		cur = pos[2][tmp];
		//cerr << pos[0][i] << ' ' << cur << '\n';
		ans = min(ans, cur - pos[0][i] + 1 - 3 * k);
	}
	if (ans > n) cout << -1;
	else cout << ans;
}

Compilation message

ho_t2.cpp: In function 'int32_t main()':
ho_t2.cpp:19:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |  for (int i = 0; i < s.size(); i++){
      |                  ~~^~~~~~~~~~
ho_t2.cpp:22:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |  for (int i = 0; i + k - 1 < pos[0].size(); i++){
      |                  ~~~~~~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:25:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |   if (tmp >= pos[1].size()) continue;
      |       ~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:28:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |   if (tmp >= pos[2].size()) continue;
      |       ~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:16:23: warning: unused variable 'st' [-Wunused-variable]
   16 |  int n, k, ans = 1e9, st, cur; cin >> n >> k;
      |                       ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 9 ms 2116 KB Output is correct
37 Correct 11 ms 2636 KB Output is correct
38 Correct 10 ms 2672 KB Output is correct
39 Correct 10 ms 2720 KB Output is correct
40 Correct 8 ms 2764 KB Output is correct
41 Correct 9 ms 2764 KB Output is correct
42 Correct 10 ms 2636 KB Output is correct
43 Correct 5 ms 1704 KB Output is correct
44 Correct 5 ms 1872 KB Output is correct
45 Correct 8 ms 2704 KB Output is correct
46 Correct 9 ms 2704 KB Output is correct
47 Correct 7 ms 2764 KB Output is correct
48 Correct 8 ms 2736 KB Output is correct
49 Correct 5 ms 1736 KB Output is correct
50 Correct 8 ms 2728 KB Output is correct
51 Correct 9 ms 2780 KB Output is correct
52 Correct 4 ms 2268 KB Output is correct
53 Correct 5 ms 2632 KB Output is correct
54 Correct 7 ms 3032 KB Output is correct
55 Correct 3 ms 3032 KB Output is correct
56 Correct 3 ms 3032 KB Output is correct