# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
364631 | 2021-02-09T15:25:43 Z | Killer2501 | JJOOII 2 (JOI20_ho_t2) | C++14 | 11 ms | 9516 KB |
#include <bits/stdc++.h> #define pb push_back #define task "sequence" #define pll pair<ll, ll> #define pii pair<vector<ll>, ll> #define fi first #define se second using ll = long long; const long long mod = 1e15+7; const ll mod1 = 1e9+1; const ll N = 2e5+5; const int base = 350; using ull = unsigned long long; using namespace std; string s, ss; ll n, m, t, k, T, cnt, tong, a[N], c[N], b[N], ans, d[N], l[N], r[N]; vector<ll> adj[N], kq; void sol() { cin >> n >> k >> s; s = " " + s; l[0] = r[n+1] = mod; for(int i = 1; i <= n; i ++) { l[i] = l[i-1] + 1; if(s[i] == 'J') { kq.pb(i); if(kq.size() >= k) { l[i] = i - kq[kq.size()-k] + 1 - k; } } } kq.clear(); for(int i = n; i > 0; i --) { r[i] = r[i+1] + 1; if(s[i] == 'I') { kq.pb(i); if(kq.size() >= k) { r[i] = kq[kq.size()-k] - i + 1 - k; } } } kq.clear(); ans = mod; for(int i = 1; i <= n; i ++) { if(s[i] == 'O') { kq.pb(i); if(kq.size() >= k) { ans = min(ans, i - kq[kq.size()-k] + 1 - k + r[i+1] + l[kq[kq.size()-k]-1]); } } } if(ans == mod)ans = -1; cout << ans; } int main() { if(fopen(task".in", "r")){ freopen(task".in", "r", stdin); freopen(task".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int ntest; ntest = 1; //cin >> ntest; //cout << (1<<30) << '\n'; while(ntest -- > 0) sol(); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 5100 KB | Output is correct |
2 | Correct | 4 ms | 5100 KB | Output is correct |
3 | Correct | 5 ms | 5100 KB | Output is correct |
4 | Correct | 5 ms | 5100 KB | Output is correct |
5 | Correct | 4 ms | 5100 KB | Output is correct |
6 | Correct | 4 ms | 5100 KB | Output is correct |
7 | Correct | 3 ms | 5100 KB | Output is correct |
8 | Correct | 4 ms | 5100 KB | Output is correct |
9 | Correct | 4 ms | 5100 KB | Output is correct |
10 | Correct | 4 ms | 5100 KB | Output is correct |
11 | Correct | 3 ms | 5100 KB | Output is correct |
12 | Correct | 3 ms | 5100 KB | Output is correct |
13 | Correct | 4 ms | 5100 KB | Output is correct |
14 | Correct | 4 ms | 5100 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 5100 KB | Output is correct |
2 | Correct | 4 ms | 5100 KB | Output is correct |
3 | Correct | 5 ms | 5100 KB | Output is correct |
4 | Correct | 5 ms | 5100 KB | Output is correct |
5 | Correct | 4 ms | 5100 KB | Output is correct |
6 | Correct | 4 ms | 5100 KB | Output is correct |
7 | Correct | 3 ms | 5100 KB | Output is correct |
8 | Correct | 4 ms | 5100 KB | Output is correct |
9 | Correct | 4 ms | 5100 KB | Output is correct |
10 | Correct | 4 ms | 5100 KB | Output is correct |
11 | Correct | 3 ms | 5100 KB | Output is correct |
12 | Correct | 3 ms | 5100 KB | Output is correct |
13 | Correct | 4 ms | 5100 KB | Output is correct |
14 | Correct | 4 ms | 5100 KB | Output is correct |
15 | Correct | 4 ms | 5100 KB | Output is correct |
16 | Correct | 3 ms | 5100 KB | Output is correct |
17 | Correct | 4 ms | 5100 KB | Output is correct |
18 | Correct | 4 ms | 5100 KB | Output is correct |
19 | Correct | 4 ms | 5100 KB | Output is correct |
20 | Correct | 4 ms | 5100 KB | Output is correct |
21 | Correct | 4 ms | 5100 KB | Output is correct |
22 | Correct | 4 ms | 5100 KB | Output is correct |
23 | Correct | 4 ms | 5120 KB | Output is correct |
24 | Correct | 4 ms | 5112 KB | Output is correct |
25 | Correct | 3 ms | 5100 KB | Output is correct |
26 | Correct | 4 ms | 5104 KB | Output is correct |
27 | Correct | 4 ms | 5100 KB | Output is correct |
28 | Correct | 4 ms | 5100 KB | Output is correct |
29 | Correct | 4 ms | 5100 KB | Output is correct |
30 | Correct | 4 ms | 5100 KB | Output is correct |
31 | Correct | 3 ms | 5100 KB | Output is correct |
32 | Correct | 4 ms | 5100 KB | Output is correct |
33 | Correct | 4 ms | 5100 KB | Output is correct |
34 | Correct | 5 ms | 5100 KB | Output is correct |
35 | Correct | 4 ms | 5100 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 5100 KB | Output is correct |
2 | Correct | 4 ms | 5100 KB | Output is correct |
3 | Correct | 5 ms | 5100 KB | Output is correct |
4 | Correct | 5 ms | 5100 KB | Output is correct |
5 | Correct | 4 ms | 5100 KB | Output is correct |
6 | Correct | 4 ms | 5100 KB | Output is correct |
7 | Correct | 3 ms | 5100 KB | Output is correct |
8 | Correct | 4 ms | 5100 KB | Output is correct |
9 | Correct | 4 ms | 5100 KB | Output is correct |
10 | Correct | 4 ms | 5100 KB | Output is correct |
11 | Correct | 3 ms | 5100 KB | Output is correct |
12 | Correct | 3 ms | 5100 KB | Output is correct |
13 | Correct | 4 ms | 5100 KB | Output is correct |
14 | Correct | 4 ms | 5100 KB | Output is correct |
15 | Correct | 4 ms | 5100 KB | Output is correct |
16 | Correct | 3 ms | 5100 KB | Output is correct |
17 | Correct | 4 ms | 5100 KB | Output is correct |
18 | Correct | 4 ms | 5100 KB | Output is correct |
19 | Correct | 4 ms | 5100 KB | Output is correct |
20 | Correct | 4 ms | 5100 KB | Output is correct |
21 | Correct | 4 ms | 5100 KB | Output is correct |
22 | Correct | 4 ms | 5100 KB | Output is correct |
23 | Correct | 4 ms | 5120 KB | Output is correct |
24 | Correct | 4 ms | 5112 KB | Output is correct |
25 | Correct | 3 ms | 5100 KB | Output is correct |
26 | Correct | 4 ms | 5104 KB | Output is correct |
27 | Correct | 4 ms | 5100 KB | Output is correct |
28 | Correct | 4 ms | 5100 KB | Output is correct |
29 | Correct | 4 ms | 5100 KB | Output is correct |
30 | Correct | 4 ms | 5100 KB | Output is correct |
31 | Correct | 3 ms | 5100 KB | Output is correct |
32 | Correct | 4 ms | 5100 KB | Output is correct |
33 | Correct | 4 ms | 5100 KB | Output is correct |
34 | Correct | 5 ms | 5100 KB | Output is correct |
35 | Correct | 4 ms | 5100 KB | Output is correct |
36 | Correct | 10 ms | 9020 KB | Output is correct |
37 | Correct | 11 ms | 9388 KB | Output is correct |
38 | Correct | 10 ms | 9388 KB | Output is correct |
39 | Correct | 10 ms | 9260 KB | Output is correct |
40 | Correct | 10 ms | 9388 KB | Output is correct |
41 | Correct | 11 ms | 9388 KB | Output is correct |
42 | Correct | 11 ms | 9388 KB | Output is correct |
43 | Correct | 8 ms | 7912 KB | Output is correct |
44 | Correct | 9 ms | 8412 KB | Output is correct |
45 | Correct | 10 ms | 9388 KB | Output is correct |
46 | Correct | 10 ms | 9388 KB | Output is correct |
47 | Correct | 11 ms | 9388 KB | Output is correct |
48 | Correct | 11 ms | 9388 KB | Output is correct |
49 | Correct | 8 ms | 8048 KB | Output is correct |
50 | Correct | 11 ms | 9388 KB | Output is correct |
51 | Correct | 10 ms | 9388 KB | Output is correct |
52 | Correct | 10 ms | 9144 KB | Output is correct |
53 | Correct | 11 ms | 9388 KB | Output is correct |
54 | Correct | 9 ms | 9388 KB | Output is correct |
55 | Correct | 8 ms | 9516 KB | Output is correct |
56 | Correct | 9 ms | 9388 KB | Output is correct |