답안 #947670

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
947670 2024-03-16T19:10:14 Z veljko JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
9 ms 3308 KB
/*****from dust I have come, dust I will be*****/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define forn(i,n) for(int i=0;i<n;i++)
int dx[8] = { 1, 0, -1, 0, -1, 1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, -1, 1, 1, -1 };
int ceil_div(int a, int b) {return a % b == 0 ? a / b : a / b + 1;}
 
const int MOD = 1000000007;
//const int MOD = 998244353;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
 
/*
int k = A.order_of_key(p[i].second);
A.erase(A.find_by_order(k));
erase element from pbds multiset
*/


 
void solve(){
    int k,n; cin >> n>> k;
    string s; cin >> s;
    int ans = 1e18;
    vector<int>j, o, i;
    forn(x,n){
        if (s[x] == 'J') j.push_back(x);
        else if (s[x] == 'O') o.push_back(x);
        else i.push_back(x);
    }
    int p1 = 0, p2 = k-1, x = 0;
    while (p2 < (int)j.size()){
        x = (p2 - p1 + 1)-k;
        auto it = upper_bound(o.begin(), o.end(), j[p2]);
        int lo = it - o.begin();
        int ro = lo + (k - 1);
        if (ro >= (int)o.size()){
            p1++; p2++;
            continue;;
        }
        x += (ro - lo + 1) - k;

        it = upper_bound(i.begin(), i.end(), o[ro]);
        int li = it - i.begin();
        int ri = li + (k - 1);
        if (ri >= (int)i.size()){
            p1++; p2++;
            continue;;
        }
        x += (ri - li + 1) - k;
        //cout <<i[ri]-j[p1]+1 - k*3<<'\n';
        ans = min(ans, (i[ri]-j[p1]+1 - k*3));
        // cout <<j[p1]<<' '<<j[p2]<<'\n';
        // cout <<o[lo]<<' '<<o[ro]<<'\n';
        // cout <<i[li]<<' '<<i[ri]<<'\n';
        p1++; p2++;
    }
    if (ans == 1e18) ans = -1;
    cout <<ans<<'\n';
    
}
 
 
int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 

 
    int t = 1; //cin >>t;
    for (int i=1;i<=t;i++){
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 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 348 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 348 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 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 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 348 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 348 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 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 456 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 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 0 ms 344 KB Output is correct
33 Correct 0 ms 600 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 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 348 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 348 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 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 456 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 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 0 ms 344 KB Output is correct
33 Correct 0 ms 600 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 8 ms 2508 KB Output is correct
37 Correct 9 ms 2996 KB Output is correct
38 Correct 9 ms 3112 KB Output is correct
39 Correct 8 ms 2984 KB Output is correct
40 Correct 7 ms 3028 KB Output is correct
41 Correct 8 ms 3052 KB Output is correct
42 Correct 9 ms 3028 KB Output is correct
43 Correct 4 ms 1968 KB Output is correct
44 Correct 5 ms 2568 KB Output is correct
45 Correct 6 ms 2968 KB Output is correct
46 Correct 6 ms 2968 KB Output is correct
47 Correct 6 ms 3032 KB Output is correct
48 Correct 6 ms 3000 KB Output is correct
49 Correct 4 ms 2024 KB Output is correct
50 Correct 6 ms 3000 KB Output is correct
51 Correct 6 ms 3028 KB Output is correct
52 Correct 3 ms 2504 KB Output is correct
53 Correct 4 ms 2896 KB Output is correct
54 Correct 4 ms 3308 KB Output is correct
55 Correct 3 ms 3280 KB Output is correct
56 Correct 2 ms 3292 KB Output is correct