답안 #229946

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
229946 2020-05-07T08:31:44 Z grt JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
12 ms 3380 KB
#include <bits/stdc++.h>
#define PB push_back
#define ST first
#define ND second
#define _ ios_base::sync_with_stdio(0); cin.tie(0);
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

using namespace std;

using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;

const int nax = 200*1000+10,INF = 1e9 +10;
int n,k;
string s;
vi posJ, posO, posI;
int nxtJ[nax], nxtI[nax];

int main() {_
	cin >> n >> k >> s;
	for(int i = 0; i < n; ++i) {
		if(s[i] == 'J') posJ.PB(i);
		if(posJ.size() < k) {
			nxtJ[i] = -1;
		} else {
			nxtJ[i] = posJ[(int)posJ.size() - k];
		}
	}
	for(int i = n-1; i >=0; --i) {
		if(s[i] == 'I') posI.PB(i);
		if(posI.size() < k) {
			nxtI[i] = -1;
		} else {
			nxtI[i] = posI[(int)posI.size()-k];
		}
	}
	int l = 0;
	int cntO = 0;
	int ans = INF;
	for(int r = 0; r < n; ++r) {
		if(s[r] == 'O') cntO++;
		while(cntO - (s[l] == 'O') >= k) {
			if(s[l] == 'O') cntO--;
			l++;
		}
		if(cntO == k) {
			int a = nxtJ[l], b = nxtI[r];
			//cout << a << " " << l << " " << r << " " << b << "\n";
			if(a == -1 || b == -1) continue;
			ans = min(ans,b-a+1 - 3*k);
		}
	}
	if(ans == INF) {
		cout << "-1";
	} else {
		cout << ans;
	}
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:24:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(posJ.size() < k) {
      ~~~~~~~~~~~~^~~
ho_t2.cpp:32:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(posI.size() < k) {
      ~~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 256 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 256 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 11 ms 2824 KB Output is correct
37 Correct 12 ms 3204 KB Output is correct
38 Correct 12 ms 3332 KB Output is correct
39 Correct 12 ms 3076 KB Output is correct
40 Correct 12 ms 3380 KB Output is correct
41 Correct 12 ms 3332 KB Output is correct
42 Correct 12 ms 3332 KB Output is correct
43 Correct 9 ms 2112 KB Output is correct
44 Correct 10 ms 2440 KB Output is correct
45 Correct 11 ms 3332 KB Output is correct
46 Correct 12 ms 3332 KB Output is correct
47 Correct 11 ms 3332 KB Output is correct
48 Correct 11 ms 3332 KB Output is correct
49 Correct 9 ms 2184 KB Output is correct
50 Correct 11 ms 3332 KB Output is correct
51 Correct 11 ms 3332 KB Output is correct
52 Correct 10 ms 2824 KB Output is correct
53 Correct 11 ms 3308 KB Output is correct
54 Correct 9 ms 2948 KB Output is correct
55 Correct 9 ms 2948 KB Output is correct
56 Correct 9 ms 2948 KB Output is correct