# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
889994 |
2023-12-20T10:39:46 Z |
avighna |
JJOOII 2 (JOI20_ho_t2) |
C++17 |
|
16 ms |
7244 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
struct Node {
ll j, o, i, idx;
Node() {}
Node(ll j, ll o, ll i, ll idx) : j(j), o(o), i(i), idx(idx) {}
};
const ll N = 2e5;
Node x[N + 1];
ll find_where_appears(char c, ll k, ll st, ll en) {
ll ost = st;
ll ans = en + 1;
while (st <= en) {
ll m = (st + en) / 2;
ll val;
if (c == 'J') {
val = x[m].j - x[ost - 1].j;
} else if (c == 'O') {
val = x[m].o - x[ost - 1].o;
} else {
val = x[m].i - x[ost - 1].i;
}
if (val >= k) {
ans = m;
en = m - 1;
} else {
st = m + 1;
}
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, k;
string s;
cin >> n >> k >> s;
s = " " + s;
x[0].j = x[0].o = x[0].i = x[0].idx = 0;
for (ll i = 1; i <= n; ++i) {
x[i] = x[i - 1];
x[i].j += s[i] == 'J';
x[i].o += s[i] == 'O';
x[i].i += s[i] == 'I';
x[i].idx = i;
}
ll ans = LLONG_MAX;
for (ll j = 1; j <= n; ++j) {
if (s[j] != 'J') {
continue;
}
ll idx = find_where_appears('J', k, j, n);
idx = find_where_appears('O', k, idx, n);
idx = find_where_appears('I', k, idx, n);
if (idx == n + 1) {
continue;
}
ans = min(ans, idx - j + 1 - 3 * k);
}
if (ans == LLONG_MAX) {
cout << "-1\n";
} else {
cout << ans << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
11 ms |
6448 KB |
Output is correct |
37 |
Correct |
12 ms |
7204 KB |
Output is correct |
38 |
Correct |
11 ms |
7244 KB |
Output is correct |
39 |
Correct |
15 ms |
6948 KB |
Output is correct |
40 |
Correct |
11 ms |
7048 KB |
Output is correct |
41 |
Correct |
14 ms |
7200 KB |
Output is correct |
42 |
Correct |
16 ms |
7204 KB |
Output is correct |
43 |
Correct |
6 ms |
5212 KB |
Output is correct |
44 |
Correct |
8 ms |
5960 KB |
Output is correct |
45 |
Correct |
10 ms |
7232 KB |
Output is correct |
46 |
Correct |
10 ms |
7204 KB |
Output is correct |
47 |
Correct |
10 ms |
7228 KB |
Output is correct |
48 |
Correct |
10 ms |
7080 KB |
Output is correct |
49 |
Correct |
7 ms |
4964 KB |
Output is correct |
50 |
Correct |
10 ms |
7204 KB |
Output is correct |
51 |
Correct |
10 ms |
7204 KB |
Output is correct |
52 |
Correct |
7 ms |
6960 KB |
Output is correct |
53 |
Correct |
7 ms |
7204 KB |
Output is correct |
54 |
Correct |
11 ms |
7204 KB |
Output is correct |
55 |
Correct |
8 ms |
7204 KB |
Output is correct |
56 |
Correct |
5 ms |
7200 KB |
Output is correct |