답안 #207816

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
207816 2020-03-09T06:35:11 Z bensonlzl JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
21 ms 3944 KB
#include <bits/stdc++.h>

using namespace std;

int N, K, nextJ[200005], nextO[200005], nextI[200005];
vector<int> posJ, posO, posI;
char x[200005];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> N >> K;
	for (int i = 1; i <= N; ++i){
		cin >> x[i];
		if (x[i] == 'J') posJ.push_back(i);
		if (x[i] == 'O') posO.push_back(i);
		if (x[i] == 'I') posI.push_back(i);
	}
	int lastJ = N+1, lastO = N+1, lastI = N+1;
	for (int i = N; i >= 1; --i){
		nextJ[i] = lastJ;
		nextO[i] = lastO;
		nextI[i] = lastI;
		if (x[i] == 'J') lastJ = i;
		if (x[i] == 'O') lastO = i;
		if (x[i] == 'I') lastI = i;
	}
	int mini = 1e9;
	for (int i = 0; i < posJ.size() - K + 1; ++i){
		int lJ = posJ[i], rJ = posJ[i+K-1];
		int lO = nextO[rJ];
		auto itO = lower_bound(posO.begin(),posO.end(),lO);
		if (itO - posO.begin() > posO.size() - K) break;
		int rO = *(itO + K - 1);
		int lI = nextI[rO];
		auto itI = lower_bound(posI.begin(),posI.end(),lI);
		if (itI - posI.begin() > posI.size() - K) break;
		int rI = *(itI + K - 1);
		mini = min(mini,rI - lJ + 1 - 3 * K);
	}
	if (mini == 1e9){
		cout << -1 << '\n';
	}
	else cout << mini << '\n';
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:29:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < posJ.size() - K + 1; ++i){
                  ~~^~~~~~~~~~~~~~~~~~~~~
ho_t2.cpp:33:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (itO - posO.begin() > posO.size() - K) break;
       ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
ho_t2.cpp:37:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (itI - posI.begin() > posI.size() - K) break;
       ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Correct 4 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 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 4 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 4 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 380 KB Output is correct
3 Correct 4 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 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 4 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 4 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 248 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 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 380 KB Output is correct
21 Correct 5 ms 508 KB Output is correct
22 Correct 5 ms 380 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 380 KB Output is correct
34 Correct 5 ms 376 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 380 KB Output is correct
3 Correct 4 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 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 4 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 4 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 248 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 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 380 KB Output is correct
21 Correct 5 ms 508 KB Output is correct
22 Correct 5 ms 380 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 380 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 21 ms 3568 KB Output is correct
37 Correct 21 ms 3816 KB Output is correct
38 Correct 21 ms 3924 KB Output is correct
39 Correct 20 ms 3944 KB Output is correct
40 Correct 16 ms 3908 KB Output is correct
41 Correct 18 ms 3924 KB Output is correct
42 Correct 21 ms 3816 KB Output is correct
43 Correct 11 ms 2800 KB Output is correct
44 Correct 12 ms 3168 KB Output is correct
45 Correct 14 ms 3812 KB Output is correct
46 Correct 14 ms 3812 KB Output is correct
47 Correct 14 ms 3940 KB Output is correct
48 Correct 14 ms 3940 KB Output is correct
49 Correct 12 ms 2800 KB Output is correct
50 Correct 14 ms 3812 KB Output is correct
51 Correct 14 ms 3940 KB Output is correct
52 Correct 13 ms 3756 KB Output is correct
53 Correct 14 ms 3944 KB Output is correct
54 Correct 12 ms 3816 KB Output is correct
55 Correct 11 ms 3828 KB Output is correct
56 Correct 10 ms 3828 KB Output is correct