답안 #997639

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
997639 2024-06-12T15:42:31 Z mariamp1 JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
14 ms 5676 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
const int N = 2e5 + 5, mod = 1e9+7;
vector<pair<int, int> > vec;
multiset<int> st;
int minn = 1e9;
int last[N];
int n; 
int pref[3][N], k;
int findd(int ind, int type){
    int l = ind; int r = n; int anss = -1;
    while(l <= r){
        int mid = l + (r-l)/2;
        if( pref[type][mid] - pref[type][ind - 1] >= k){
            anss = mid;
            r = mid - 1;
        }else l = mid + 1;
    }
    return anss;
}
int32_t main(){
	cin >> n >> k;
    string s; cin >> s;
    s = "*" + s;
    for(int i = 1; i <= n; i++){
        pref[0][i] = pref[0][i - 1] + (s[i] == 'J');
        pref[1][i] = pref[1][i - 1] + (s[i] == 'O');
        pref[2][i] = pref[2][i - 1] + (s[i] == 'I');
    }
    for(int i = 1; i <= n; i++){
        if(s[i] != 'J') continue;
        int mekJ = findd(i, 0);
        if (mekJ == -1) break;
        int mekO = findd(mekJ, 1);
        if (mekO == -1) break;
        int mekI = findd(mekO, 2);
        if (mekI == -1) break;
        int l = i;
        int r = mekI;
        minn = min(minn, r - l + 1 - 3 * k);
    }
    if(minn == 1e9) cout << -1 << endl;
    else 
        cout << minn << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 424 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 1 ms 348 KB Output is correct
8 Correct 0 ms 416 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 424 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 1 ms 348 KB Output is correct
8 Correct 0 ms 416 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 1 ms 348 KB Output is correct
18 Correct 0 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 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 512 KB Output is correct
28 Correct 1 ms 344 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 348 KB Output is correct
33 Correct 0 ms 448 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 424 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 1 ms 348 KB Output is correct
8 Correct 0 ms 416 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 1 ms 348 KB Output is correct
18 Correct 0 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 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 512 KB Output is correct
28 Correct 1 ms 344 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 348 KB Output is correct
33 Correct 0 ms 448 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 10 ms 5328 KB Output is correct
37 Correct 12 ms 5672 KB Output is correct
38 Correct 11 ms 5676 KB Output is correct
39 Correct 12 ms 5508 KB Output is correct
40 Correct 8 ms 5668 KB Output is correct
41 Correct 11 ms 5416 KB Output is correct
42 Correct 14 ms 5672 KB Output is correct
43 Correct 3 ms 3440 KB Output is correct
44 Correct 4 ms 4288 KB Output is correct
45 Correct 5 ms 5436 KB Output is correct
46 Correct 8 ms 5672 KB Output is correct
47 Correct 6 ms 5580 KB Output is correct
48 Correct 5 ms 5672 KB Output is correct
49 Correct 4 ms 3944 KB Output is correct
50 Correct 8 ms 5668 KB Output is correct
51 Correct 5 ms 5672 KB Output is correct
52 Correct 5 ms 5276 KB Output is correct
53 Correct 5 ms 5672 KB Output is correct
54 Correct 10 ms 5668 KB Output is correct
55 Correct 7 ms 5416 KB Output is correct
56 Correct 6 ms 5656 KB Output is correct