# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
702735 | 2023-02-25T01:32:08 Z | vjudge1 | JJOOII 2 (JOI20_ho_t2) | C++14 | 14 ms | 2532 KB |
#include "bits/stdc++.h" using namespace std; const int MAXN = 2e5+5; int pref_o[MAXN]; int main() { int n, k; cin >> n >> k; string s; cin >> s; vector<int> j_idx, i_idx; for(int i = 0; i < n; i++) { pref_o[i] = 0; if(i > 0) pref_o[i] = pref_o[i - 1]; if(s[i] == 'J') j_idx.push_back(i); else if(s[i] == 'O') pref_o[i]++; else i_idx.push_back(i); } int ans = 1e9; for(int i = k - 1; i < j_idx.size(); i++) { int j_dif = j_idx[i] - j_idx[i - (k - 1)] - (k-2) - 1; int l = 0, r = i_idx.size() - 1 - k + 1; while(l <= r) { int m = (l + r) / 2; // First i; if(i_idx[m] < j_idx[i]) { l = m + 1; continue; } int temp = j_dif + (i_idx[m + k - 1] - i_idx[m] - (k-2) - 1); int first_i = i_idx[m]; int last_j = j_idx[i]; if(pref_o[first_i] - pref_o[last_j] >= k) { temp += first_i - last_j - k - 1; ans = min(ans, temp); r = m - 1; } else l = m + 1; //cout << ans << " " << j_idx[i] << " " << i_idx[m] << " " << i << " " << m << "\n"; } } if(ans == 1e9) cout << "-1\n"; else cout << ans << "\n"; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 308 KB | Output is correct |
6 | Correct | 1 ms | 312 KB | Output is correct |
7 | Correct | 0 ms | 312 KB | Output is correct |
8 | Correct | 1 ms | 312 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 308 KB | Output is correct |
6 | Correct | 1 ms | 312 KB | Output is correct |
7 | Correct | 0 ms | 312 KB | Output is correct |
8 | Correct | 1 ms | 312 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 312 KB | Output is correct |
16 | Correct | 1 ms | 340 KB | Output is correct |
17 | Correct | 1 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 340 KB | Output is correct |
19 | Correct | 1 ms | 340 KB | Output is correct |
20 | Correct | 1 ms | 312 KB | Output is correct |
21 | Correct | 1 ms | 340 KB | Output is correct |
22 | Correct | 1 ms | 340 KB | Output is correct |
23 | Correct | 0 ms | 312 KB | Output is correct |
24 | Correct | 1 ms | 340 KB | Output is correct |
25 | Correct | 1 ms | 340 KB | Output is correct |
26 | Correct | 1 ms | 340 KB | Output is correct |
27 | Correct | 1 ms | 308 KB | Output is correct |
28 | Correct | 1 ms | 340 KB | Output is correct |
29 | Correct | 1 ms | 340 KB | Output is correct |
30 | Correct | 1 ms | 340 KB | Output is correct |
31 | Correct | 0 ms | 212 KB | Output is correct |
32 | Correct | 1 ms | 312 KB | Output is correct |
33 | Correct | 1 ms | 340 KB | Output is correct |
34 | Correct | 1 ms | 316 KB | Output is correct |
35 | Correct | 0 ms | 312 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 308 KB | Output is correct |
6 | Correct | 1 ms | 312 KB | Output is correct |
7 | Correct | 0 ms | 312 KB | Output is correct |
8 | Correct | 1 ms | 312 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 312 KB | Output is correct |
16 | Correct | 1 ms | 340 KB | Output is correct |
17 | Correct | 1 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 340 KB | Output is correct |
19 | Correct | 1 ms | 340 KB | Output is correct |
20 | Correct | 1 ms | 312 KB | Output is correct |
21 | Correct | 1 ms | 340 KB | Output is correct |
22 | Correct | 1 ms | 340 KB | Output is correct |
23 | Correct | 0 ms | 312 KB | Output is correct |
24 | Correct | 1 ms | 340 KB | Output is correct |
25 | Correct | 1 ms | 340 KB | Output is correct |
26 | Correct | 1 ms | 340 KB | Output is correct |
27 | Correct | 1 ms | 308 KB | Output is correct |
28 | Correct | 1 ms | 340 KB | Output is correct |
29 | Correct | 1 ms | 340 KB | Output is correct |
30 | Correct | 1 ms | 340 KB | Output is correct |
31 | Correct | 0 ms | 212 KB | Output is correct |
32 | Correct | 1 ms | 312 KB | Output is correct |
33 | Correct | 1 ms | 340 KB | Output is correct |
34 | Correct | 1 ms | 316 KB | Output is correct |
35 | Correct | 0 ms | 312 KB | Output is correct |
36 | Correct | 14 ms | 1912 KB | Output is correct |
37 | Correct | 12 ms | 2292 KB | Output is correct |
38 | Correct | 12 ms | 2400 KB | Output is correct |
39 | Correct | 14 ms | 2380 KB | Output is correct |
40 | Correct | 9 ms | 2328 KB | Output is correct |
41 | Correct | 11 ms | 2388 KB | Output is correct |
42 | Correct | 12 ms | 2352 KB | Output is correct |
43 | Correct | 6 ms | 1512 KB | Output is correct |
44 | Correct | 7 ms | 1744 KB | Output is correct |
45 | Correct | 9 ms | 2348 KB | Output is correct |
46 | Correct | 9 ms | 2360 KB | Output is correct |
47 | Correct | 9 ms | 2352 KB | Output is correct |
48 | Correct | 9 ms | 2384 KB | Output is correct |
49 | Correct | 6 ms | 1536 KB | Output is correct |
50 | Correct | 8 ms | 2388 KB | Output is correct |
51 | Correct | 11 ms | 2364 KB | Output is correct |
52 | Correct | 8 ms | 2084 KB | Output is correct |
53 | Correct | 8 ms | 2408 KB | Output is correct |
54 | Correct | 9 ms | 2396 KB | Output is correct |
55 | Correct | 8 ms | 2532 KB | Output is correct |
56 | Correct | 6 ms | 2508 KB | Output is correct |