Submission #286151

# Submission time Handle Problem Language Result Execution time Memory
286151 2020-08-30T07:31:00 Z reymontada61 JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
43 ms 2056 KB
#include <bits/stdc++.h>
using namespace std;

int n, k;
string s;
vector<int> tr[3];

int start(int at) {
	int jind = lower_bound(tr[0].begin(), tr[0].end(), at) - tr[0].begin();
	if (jind + k >= tr[0].size()) return INT_MAX;
	int oind = lower_bound(tr[1].begin(), tr[1].end(), tr[0][jind+k]) - tr[1].begin();
	if (oind + k >= tr[1].size()) return INT_MAX;
	int iind = lower_bound(tr[2].begin(), tr[2].end(), tr[1][oind+k]) - tr[2].begin();
	if (iind + k >= tr[2].size()) return INT_MAX;
	return tr[2][iind+k];
}

signed main() {

	cin >> n >> k;
	cin >> s;
	k--;

	for (int i=1; i<=n; i++) {
		if (s[i-1] == 'J') tr[0].push_back(i);
		if (s[i-1] == 'O') tr[1].push_back(i);
		if (s[i-1] == 'I') tr[2].push_back(i);
	}
	
	int le = INT_MAX;
	
	for (int i=1; i<=n; i++) {
		le = min(le, start(i) - i + 1);
	}
	
	if (le > n) {
		cout << -1 << endl;
	} 
	else {
		cout << le - 3 * (k+1) << endl;
	}

}

Compilation message

ho_t2.cpp: In function 'int start(int)':
ho_t2.cpp:10:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  if (jind + k >= tr[0].size()) return INT_MAX;
      |      ~~~~~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:12:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |  if (oind + k >= tr[1].size()) return INT_MAX;
      |      ~~~~~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:14:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  if (iind + k >= tr[2].size()) return INT_MAX;
      |      ~~~~~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 0 ms 256 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 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 0 ms 256 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 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 256 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 512 KB Output is correct
31 Correct 1 ms 404 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 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 0 ms 256 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 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 256 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 512 KB Output is correct
31 Correct 1 ms 404 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 34 ms 1544 KB Output is correct
37 Correct 37 ms 1868 KB Output is correct
38 Correct 39 ms 2040 KB Output is correct
39 Correct 43 ms 2052 KB Output is correct
40 Correct 30 ms 2024 KB Output is correct
41 Correct 38 ms 2040 KB Output is correct
42 Correct 36 ms 1928 KB Output is correct
43 Correct 18 ms 1288 KB Output is correct
44 Correct 22 ms 1528 KB Output is correct
45 Correct 29 ms 1960 KB Output is correct
46 Correct 29 ms 1924 KB Output is correct
47 Correct 29 ms 2056 KB Output is correct
48 Correct 39 ms 2056 KB Output is correct
49 Correct 23 ms 1292 KB Output is correct
50 Correct 31 ms 1928 KB Output is correct
51 Correct 30 ms 1928 KB Output is correct
52 Correct 21 ms 1612 KB Output is correct
53 Correct 24 ms 1868 KB Output is correct
54 Correct 22 ms 2056 KB Output is correct
55 Correct 19 ms 2056 KB Output is correct
56 Correct 19 ms 2056 KB Output is correct