Submission #888163

# Submission time Handle Problem Language Result Execution time Memory
888163 2023-12-16T09:12:07 Z Unforgettablepl JJOOII 2 (JOI20_ho_t2) C++17
13 / 100
2000 ms 5364 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
const int INF = INT64_MAX;

int prefix[200001][3];

int32_t main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    for(int i=1;i<=n;i++){
        char a;cin>>a;
        prefix[i][0]=prefix[i-1][0];
        prefix[i][1]=prefix[i-1][1];
        prefix[i][2]=prefix[i-1][2];
        if(a=='J')prefix[i][0]++;
        else if(a=='O')prefix[i][1]++;
        else prefix[i][2]++;
    }
    int ans = INF;
    for(int l=1;l<=n;l++){
        if(prefix[l][0]-prefix[l-1][0]==0)continue;
        if(prefix[n][0]-prefix[l-1][0]<k)break;
        int mid1 = l-1;
        for(int jump=1;jump;jump/=2){
            if(mid1+jump>n)continue;
            while(prefix[mid1+jump][0]-prefix[l-1][0]<k)mid1+=jump;
        }
        mid1++;
        if(prefix[n][1]-prefix[mid1-1][1]<k)break;
        int mid2 = mid1-1;
        for(int jump=1;jump;jump/=2){
            if(mid2+jump>n)continue;
            while(prefix[mid2+jump][1]-prefix[mid1-1][1]<k)mid2+=jump;
        }
        mid2++;
        if(prefix[n][2]-prefix[mid2-1][2]<k)break;
        int r = mid2-1;
        for(int jump=1;jump;jump/=2){
            if(r+jump>n)continue;
            while(prefix[r+jump][2]-prefix[mid2-1][2]<k)r+=jump;
        }
        r++;
        ans = min(ans,r-l);
    }
    if(ans==INF)cout << "-1\n";
    else cout << ans+1-3*k << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 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 344 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 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 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 344 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 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 456 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 504 KB Output is correct
33 Correct 2 ms 348 KB Output is correct
34 Correct 2 ms 344 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 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 344 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 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 456 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 504 KB Output is correct
33 Correct 2 ms 348 KB Output is correct
34 Correct 2 ms 344 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 6 ms 4956 KB Output is correct
37 Correct 7 ms 5208 KB Output is correct
38 Correct 7 ms 5212 KB Output is correct
39 Correct 1250 ms 5284 KB Output is correct
40 Correct 1174 ms 5208 KB Output is correct
41 Correct 1846 ms 5324 KB Output is correct
42 Correct 289 ms 5328 KB Output is correct
43 Correct 3 ms 4696 KB Output is correct
44 Correct 4 ms 4700 KB Output is correct
45 Correct 5 ms 5344 KB Output is correct
46 Correct 5 ms 5200 KB Output is correct
47 Correct 5 ms 5192 KB Output is correct
48 Correct 5 ms 5212 KB Output is correct
49 Correct 4 ms 4700 KB Output is correct
50 Correct 5 ms 5212 KB Output is correct
51 Correct 5 ms 5208 KB Output is correct
52 Correct 5 ms 5364 KB Output is correct
53 Correct 5 ms 5212 KB Output is correct
54 Execution timed out 2085 ms 5212 KB Time limit exceeded
55 Halted 0 ms 0 KB -