Submission #516974

# Submission time Handle Problem Language Result Execution time Memory
516974 2022-01-22T09:50:04 Z kevinxiehk JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
4 ms 3488 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb emplace_back
#define fi first
#define se second
#define int long long
#define inf 1e18
#define ick cout<<"ickbmi32.9\n"
using namespace std;
bool isprime(int k) {
    for(int i = 2; i <= sqrt(k); i++) if(k % i == 0) return false; 
    return true;    
}
int bm(int a, int b, int mod) {
    if(b == 0) return 1; 
    int t = bm(a, b / 2, mod); 
    t = t * t % mod; 
    return (b % 2 == 1 ? t * a % mod : t);
}
int inv(int a, int mod) {return bm(a, mod - 2, mod);}
int n, k;
string s;
int jpos[200005], ipos[200005], ops[200005];// 1-based!!!
signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(0); cout.tie(0);
    cin >> n >> k >> s; k--;
    s = "_" + s;
    int jcnt = 0, icnt = 0;
    for(int i = 1; i <= n; i++) {
        if(s[i] == 'J') jpos[jcnt++] = i;
        else if(s[i] == 'I') ipos[icnt++] = i;
        else ops[i]++;
        ops[i] += ops[i - 1];
    }
    int ans = inf;
    int rpt = 0;
    for(int i = 0; i < jcnt - k; i++) {
        while(rpt + k < icnt && ops[ipos[rpt]] - ops[jpos[i + k]] <= k) rpt++;
        if(rpt + k >= icnt) break;
        ans = min(ans, ipos[rpt + k] - jpos[i] - 2 - 3 * k);
    }
    if(ans == inf) ans = -1;
    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 0 ms 312 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 0 ms 312 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 316 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 0 ms 324 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 0 ms 320 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 0 ms 312 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 316 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 0 ms 324 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 0 ms 320 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 4 ms 3224 KB Output is correct
37 Correct 4 ms 3452 KB Output is correct
38 Correct 4 ms 3348 KB Output is correct
39 Correct 4 ms 3348 KB Output is correct
40 Correct 4 ms 3348 KB Output is correct
41 Correct 4 ms 3360 KB Output is correct
42 Correct 4 ms 3348 KB Output is correct
43 Correct 2 ms 2324 KB Output is correct
44 Correct 4 ms 2752 KB Output is correct
45 Correct 3 ms 3348 KB Output is correct
46 Correct 4 ms 3340 KB Output is correct
47 Correct 4 ms 3344 KB Output is correct
48 Correct 4 ms 3336 KB Output is correct
49 Correct 3 ms 2260 KB Output is correct
50 Correct 4 ms 3352 KB Output is correct
51 Correct 4 ms 3336 KB Output is correct
52 Correct 3 ms 3228 KB Output is correct
53 Correct 4 ms 3348 KB Output is correct
54 Correct 3 ms 3488 KB Output is correct
55 Correct 3 ms 3468 KB Output is correct
56 Correct 4 ms 3340 KB Output is correct