# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
797271 | 2023-07-29T08:42:05 Z | n3rm1n | JJOOII 2 (JOI20_ho_t2) | C++17 | 8 ms | 3284 KB |
#include<bits/stdc++.h> #define endl '\n' using namespace std; const int MAXN = 2e5 + 10; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } int n, k; char s[MAXN]; void read() { cin >> n >> k; for (int i = 1; i <= n; ++ i) cin >> s[i]; } int dp0[MAXN], dp1[MAXN]; int cnt[MAXN]; void precompute() { deque < int > q; for (int i = n; i >= 1; -- i) { if(s[i] == 'J')q.push_back(i); if(q.size() > k)q.pop_front(); if(q.size() < k)dp0[i] = n+1; else dp0[i] = q.front(); } q.clear(); for (int i = 1; i <= n; ++ i) { if(s[i] == 'I')q.push_back(i); if(q.size() > k)q.pop_front(); if(q.size() < k)dp1[i] = 0; else dp1[i] = q.front(); } for (int i = 1; i <= n; ++ i) { cnt[i] = cnt[i-1]; if(s[i] == 'O')cnt[i] ++; } /* for (int i = 1; i <= n; ++ i) cout << dp0[i] << " "; cout << endl; for (int i = 1; i <= n; ++ i) cout << dp1[i] << " "; cout << endl; */ } bool check(int x) { for (int i = 0; i <= x; ++ i) /// how much we delete from the front { int lastj = dp0[i+1]; int firsti = dp1[n - (x - i)]; if(lastj > firsti)continue; if(cnt[firsti - 1] - cnt[lastj] >= k)return true; } return false; } void solve() { int left = 0, right = n - 3*k, mid, ans = -1; while(left <= right) { mid = (left + right) / 2; if(check(mid)) { ans = mid; left = mid + 1; } else right = mid - 1; } if(ans == -1)cout << -1 << endl; else cout << n - 3*k - ans << endl; } int main() { speed(); read(); precompute(); solve(); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 0 ms | 328 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 328 KB | Output is correct |
12 | Correct | 0 ms | 340 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 0 ms | 328 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 328 KB | Output is correct |
12 | Correct | 0 ms | 340 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 320 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 | 340 KB | Output is correct |
21 | Correct | 1 ms | 340 KB | Output is correct |
22 | Correct | 1 ms | 328 KB | Output is correct |
23 | Correct | 1 ms | 340 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 | 340 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 | 1 ms | 340 KB | Output is correct |
32 | Correct | 1 ms | 340 KB | Output is correct |
33 | Correct | 1 ms | 340 KB | Output is correct |
34 | Correct | 1 ms | 340 KB | Output is correct |
35 | Correct | 1 ms | 328 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 0 ms | 328 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 0 ms | 328 KB | Output is correct |
12 | Correct | 0 ms | 340 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 320 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 | 340 KB | Output is correct |
21 | Correct | 1 ms | 340 KB | Output is correct |
22 | Correct | 1 ms | 328 KB | Output is correct |
23 | Correct | 1 ms | 340 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 | 340 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 | 1 ms | 340 KB | Output is correct |
32 | Correct | 1 ms | 340 KB | Output is correct |
33 | Correct | 1 ms | 340 KB | Output is correct |
34 | Correct | 1 ms | 340 KB | Output is correct |
35 | Correct | 1 ms | 328 KB | Output is correct |
36 | Correct | 6 ms | 2772 KB | Output is correct |
37 | Correct | 6 ms | 3028 KB | Output is correct |
38 | Correct | 6 ms | 3028 KB | Output is correct |
39 | Correct | 7 ms | 3028 KB | Output is correct |
40 | Correct | 7 ms | 3028 KB | Output is correct |
41 | Correct | 7 ms | 3016 KB | Output is correct |
42 | Correct | 8 ms | 3028 KB | Output is correct |
43 | Correct | 4 ms | 2004 KB | Output is correct |
44 | Correct | 5 ms | 2516 KB | Output is correct |
45 | Correct | 6 ms | 3128 KB | Output is correct |
46 | Correct | 6 ms | 3088 KB | Output is correct |
47 | Correct | 6 ms | 3084 KB | Output is correct |
48 | Correct | 6 ms | 3060 KB | Output is correct |
49 | Correct | 4 ms | 2132 KB | Output is correct |
50 | Correct | 7 ms | 3156 KB | Output is correct |
51 | Correct | 7 ms | 3144 KB | Output is correct |
52 | Correct | 8 ms | 3280 KB | Output is correct |
53 | Correct | 6 ms | 3284 KB | Output is correct |
54 | Correct | 6 ms | 3024 KB | Output is correct |
55 | Correct | 5 ms | 3184 KB | Output is correct |
56 | Correct | 5 ms | 3280 KB | Output is correct |