Submission #260830

# Submission time Handle Problem Language Result Execution time Memory
260830 2020-08-11T04:55:48 Z sahil_k JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
30 ms 2560 KB
#include <iostream>
#include <deque>
using namespace std;
#define MAXN 200005
int n, k;
char s[MAXN];
int last[MAXN];
int temp[MAXN];
deque<int> dq;
int prv;
int main () {
	cin >> n >> k;
	for (int i=0; i<n; i++) {
		cin >> s[i];
		if (s[i] == 'I') last[i] = i;
	}
	for (int i=n-1; i>=0; i--) {
		if (s[i] != 'I') continue;
		dq.push_front(i);
		if (dq.size() > k) dq.pop_back();
		if (dq.size() == k) {
			temp[i] = last[dq.back()];
		} else {
			temp[i] = 1e8;
		}
	}
	for (int i=0; i<n; i++) last[i] = temp[i];
	prv = -1;
	for (int i=n-1; i>=0; i--) {
		if (s[i] == 'I') {
			prv = i;
			continue;
		}
		if (s[i] == 'O') {
			if (prv == -1) {
				temp[i] = 1e8;
			} else {
				temp[i] = last[prv];
			}
		}
	}
	for (int i=0; i<n; i++) last[i] = temp[i];
	dq.clear();
	for (int i=n-1; i>=0; i--) {
		if (s[i] != 'O') continue;
		dq.push_front(i);
		if (dq.size() > k) dq.pop_back();
		if (dq.size() == k) {
			temp[i] = last[dq.back()];
		} else {
			temp[i] = 1e8;
		}
	}
	for (int i=0; i<n; i++) last[i] = temp[i];
	prv = -1;
	for (int i=n-1; i>=0; i--) {
		if (s[i] == 'O') {
			prv = i;
			continue;
		}
		if (s[i] == 'J') {
			if (prv == -1) {
				temp[i] = 1e8;
			} else {
				temp[i] = last[prv];
			}
		}
	}
	for (int i=0; i<n; i++) last[i] = temp[i];
	dq.clear();
	for (int i=n-1; i>=0; i--) {
		if (s[i] != 'J') continue;
		dq.push_front(i);
		if (dq.size() > k) dq.pop_back();
		if (dq.size() == k) {
			temp[i] = last[dq.back()];
		} else {
			temp[i] = 1e8;
		}
	}
	for (int i=0; i<n; i++) last[i] = temp[i];
	int o = 1e8;
	for (int i=0; i<n; i++) {
		if (s[i] != 'J') continue;
		if (last[i] == 1e8) continue;
		o = min(o, last[i]-i+1-3*k);
	}
	cout << (o == 1e8 ? -1 : o) << endl;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:20:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (dq.size() > k) dq.pop_back();
       ~~~~~~~~~~^~~
ho_t2.cpp:21:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (dq.size() == k) {
       ~~~~~~~~~~^~~~
ho_t2.cpp:47:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (dq.size() > k) dq.pop_back();
       ~~~~~~~~~~^~~
ho_t2.cpp:48:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (dq.size() == k) {
       ~~~~~~~~~~^~~~
ho_t2.cpp:74:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (dq.size() > k) dq.pop_back();
       ~~~~~~~~~~^~~
ho_t2.cpp:75:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (dq.size() == k) {
       ~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 26 ms 2176 KB Output is correct
37 Correct 28 ms 2424 KB Output is correct
38 Correct 28 ms 2296 KB Output is correct
39 Correct 27 ms 2300 KB Output is correct
40 Correct 28 ms 2304 KB Output is correct
41 Correct 30 ms 2300 KB Output is correct
42 Correct 28 ms 2308 KB Output is correct
43 Correct 17 ms 1536 KB Output is correct
44 Correct 21 ms 1920 KB Output is correct
45 Correct 27 ms 2304 KB Output is correct
46 Correct 28 ms 2296 KB Output is correct
47 Correct 29 ms 2296 KB Output is correct
48 Correct 27 ms 2296 KB Output is correct
49 Correct 19 ms 1664 KB Output is correct
50 Correct 28 ms 2304 KB Output is correct
51 Correct 28 ms 2424 KB Output is correct
52 Correct 26 ms 2432 KB Output is correct
53 Correct 27 ms 2552 KB Output is correct
54 Correct 22 ms 2304 KB Output is correct
55 Correct 24 ms 2424 KB Output is correct
56 Correct 21 ms 2560 KB Output is correct