# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
203462 |
2020-02-20T19:22:43 Z |
tri |
JJOOII 2 (JOI20_ho_t2) |
C++14 |
|
22 ms |
3968 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
#define pb push_back
#define f first
#define s second
const int MAXN = 2e5 + 10;
int N, K;
string txt;
int nums[MAXN];
vi pos[3];
int posI[MAXN];
int nxt[MAXN];
int toInt(char inp) {
if (inp == 'J') {
return 0;
} else if (inp == 'O') {
return 1;
} else {
assert(inp == 'I');
return 2;
}
}
int main() {
cin >> N >> K;
cin >> txt;
for (int i = 0; i < N; i++) {
nums[i] = toInt(txt[i]);
posI[i] = pos[nums[i]].size();
pos[nums[i]].pb(i);
}
int last[] = {-1, -1, -1};
fill(nxt, nxt + MAXN, -1);
for (int i = N - 1; i >= 0; i--) {
if (nums[i] < 2) {
nxt[i] = last[nums[i] + 1];
}
last[nums[i]] = i;
}
int ans = 1e9;
for (int fJ = 0; fJ < N; fJ++) {
if (nums[fJ] != 0) {
continue;
}
if (posI[fJ] + K - 1 >= pos[0].size()) {
continue;
}
int lJ = pos[0][posI[fJ] + K - 1];
int fO = nxt[lJ];
if (fO == -1) {
continue;
}
if (posI[fO] + K - 1 >= pos[1].size()) {
continue;
}
int lO = pos[1][posI[fO] + K - 1];
int fI = nxt[lO];
if (fI == -1) {
continue;
}
if (posI[fI] + K - 1 >= pos[2].size()) {
continue;
}
int lI = pos[2][posI[fI] + K - 1];
ans = min(ans, lI - fJ + 1 - 3 * K);
}
if (ans >= 1e9) {
ans = -1;
}
cout << ans << endl;
}
Compilation message
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:68:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (posI[fJ] + K - 1 >= pos[0].size()) {
~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:78:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (posI[fO] + K - 1 >= pos[1].size()) {
~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:88:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (posI[fI] + K - 1 >= pos[2].size()) {
~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1144 KB |
Output is correct |
2 |
Correct |
5 ms |
1144 KB |
Output is correct |
3 |
Correct |
6 ms |
1144 KB |
Output is correct |
4 |
Correct |
5 ms |
1144 KB |
Output is correct |
5 |
Correct |
5 ms |
1144 KB |
Output is correct |
6 |
Correct |
5 ms |
1144 KB |
Output is correct |
7 |
Correct |
5 ms |
1144 KB |
Output is correct |
8 |
Correct |
5 ms |
1144 KB |
Output is correct |
9 |
Correct |
5 ms |
1144 KB |
Output is correct |
10 |
Correct |
5 ms |
1144 KB |
Output is correct |
11 |
Correct |
5 ms |
1144 KB |
Output is correct |
12 |
Correct |
5 ms |
1144 KB |
Output is correct |
13 |
Correct |
5 ms |
1144 KB |
Output is correct |
14 |
Correct |
5 ms |
1144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1144 KB |
Output is correct |
2 |
Correct |
5 ms |
1144 KB |
Output is correct |
3 |
Correct |
6 ms |
1144 KB |
Output is correct |
4 |
Correct |
5 ms |
1144 KB |
Output is correct |
5 |
Correct |
5 ms |
1144 KB |
Output is correct |
6 |
Correct |
5 ms |
1144 KB |
Output is correct |
7 |
Correct |
5 ms |
1144 KB |
Output is correct |
8 |
Correct |
5 ms |
1144 KB |
Output is correct |
9 |
Correct |
5 ms |
1144 KB |
Output is correct |
10 |
Correct |
5 ms |
1144 KB |
Output is correct |
11 |
Correct |
5 ms |
1144 KB |
Output is correct |
12 |
Correct |
5 ms |
1144 KB |
Output is correct |
13 |
Correct |
5 ms |
1144 KB |
Output is correct |
14 |
Correct |
5 ms |
1144 KB |
Output is correct |
15 |
Correct |
5 ms |
1144 KB |
Output is correct |
16 |
Correct |
5 ms |
1144 KB |
Output is correct |
17 |
Correct |
5 ms |
1144 KB |
Output is correct |
18 |
Correct |
5 ms |
1144 KB |
Output is correct |
19 |
Correct |
6 ms |
1164 KB |
Output is correct |
20 |
Correct |
6 ms |
1144 KB |
Output is correct |
21 |
Correct |
5 ms |
1144 KB |
Output is correct |
22 |
Correct |
6 ms |
1144 KB |
Output is correct |
23 |
Correct |
5 ms |
1144 KB |
Output is correct |
24 |
Correct |
6 ms |
1144 KB |
Output is correct |
25 |
Correct |
5 ms |
1144 KB |
Output is correct |
26 |
Correct |
5 ms |
1144 KB |
Output is correct |
27 |
Correct |
5 ms |
1144 KB |
Output is correct |
28 |
Correct |
5 ms |
1144 KB |
Output is correct |
29 |
Correct |
6 ms |
1144 KB |
Output is correct |
30 |
Correct |
5 ms |
1144 KB |
Output is correct |
31 |
Correct |
5 ms |
1144 KB |
Output is correct |
32 |
Correct |
5 ms |
1144 KB |
Output is correct |
33 |
Correct |
5 ms |
1144 KB |
Output is correct |
34 |
Correct |
5 ms |
1144 KB |
Output is correct |
35 |
Correct |
5 ms |
1144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1144 KB |
Output is correct |
2 |
Correct |
5 ms |
1144 KB |
Output is correct |
3 |
Correct |
6 ms |
1144 KB |
Output is correct |
4 |
Correct |
5 ms |
1144 KB |
Output is correct |
5 |
Correct |
5 ms |
1144 KB |
Output is correct |
6 |
Correct |
5 ms |
1144 KB |
Output is correct |
7 |
Correct |
5 ms |
1144 KB |
Output is correct |
8 |
Correct |
5 ms |
1144 KB |
Output is correct |
9 |
Correct |
5 ms |
1144 KB |
Output is correct |
10 |
Correct |
5 ms |
1144 KB |
Output is correct |
11 |
Correct |
5 ms |
1144 KB |
Output is correct |
12 |
Correct |
5 ms |
1144 KB |
Output is correct |
13 |
Correct |
5 ms |
1144 KB |
Output is correct |
14 |
Correct |
5 ms |
1144 KB |
Output is correct |
15 |
Correct |
5 ms |
1144 KB |
Output is correct |
16 |
Correct |
5 ms |
1144 KB |
Output is correct |
17 |
Correct |
5 ms |
1144 KB |
Output is correct |
18 |
Correct |
5 ms |
1144 KB |
Output is correct |
19 |
Correct |
6 ms |
1164 KB |
Output is correct |
20 |
Correct |
6 ms |
1144 KB |
Output is correct |
21 |
Correct |
5 ms |
1144 KB |
Output is correct |
22 |
Correct |
6 ms |
1144 KB |
Output is correct |
23 |
Correct |
5 ms |
1144 KB |
Output is correct |
24 |
Correct |
6 ms |
1144 KB |
Output is correct |
25 |
Correct |
5 ms |
1144 KB |
Output is correct |
26 |
Correct |
5 ms |
1144 KB |
Output is correct |
27 |
Correct |
5 ms |
1144 KB |
Output is correct |
28 |
Correct |
5 ms |
1144 KB |
Output is correct |
29 |
Correct |
6 ms |
1144 KB |
Output is correct |
30 |
Correct |
5 ms |
1144 KB |
Output is correct |
31 |
Correct |
5 ms |
1144 KB |
Output is correct |
32 |
Correct |
5 ms |
1144 KB |
Output is correct |
33 |
Correct |
5 ms |
1144 KB |
Output is correct |
34 |
Correct |
5 ms |
1144 KB |
Output is correct |
35 |
Correct |
5 ms |
1144 KB |
Output is correct |
36 |
Correct |
20 ms |
3584 KB |
Output is correct |
37 |
Correct |
22 ms |
3968 KB |
Output is correct |
38 |
Correct |
21 ms |
3940 KB |
Output is correct |
39 |
Correct |
21 ms |
3832 KB |
Output is correct |
40 |
Correct |
21 ms |
3924 KB |
Output is correct |
41 |
Correct |
22 ms |
3940 KB |
Output is correct |
42 |
Correct |
21 ms |
3828 KB |
Output is correct |
43 |
Correct |
15 ms |
2944 KB |
Output is correct |
44 |
Correct |
18 ms |
3308 KB |
Output is correct |
45 |
Correct |
22 ms |
3960 KB |
Output is correct |
46 |
Correct |
22 ms |
3824 KB |
Output is correct |
47 |
Correct |
21 ms |
3956 KB |
Output is correct |
48 |
Correct |
22 ms |
3956 KB |
Output is correct |
49 |
Correct |
16 ms |
2936 KB |
Output is correct |
50 |
Correct |
21 ms |
3820 KB |
Output is correct |
51 |
Correct |
22 ms |
3828 KB |
Output is correct |
52 |
Correct |
20 ms |
3652 KB |
Output is correct |
53 |
Correct |
22 ms |
3768 KB |
Output is correct |
54 |
Correct |
19 ms |
3712 KB |
Output is correct |
55 |
Correct |
19 ms |
3712 KB |
Output is correct |
56 |
Correct |
20 ms |
3832 KB |
Output is correct |