답안 #724267

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
724267 2023-04-15T02:25:05 Z Cookie JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
18 ms 4256 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("WINTER.inp");
ofstream fout("WINTER.out");
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
const ll mod = 1e9 + 7;
const int mxn = 2e5 + 5, mxm = 1e5;
int n, k;
string s;
int dp[mxn + 1][3];
vt<int>J, O, I;
signed main(){
    
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> k >> s;
    forr(i, 0, n){
        if(s[i] == 'J')J.pb(i + 1);
        else if(s[i] == 'O')O.pb(i + 1);
        else I.pb(i + 1);
    }
    forr(i, 0, n + 1){
        forr(j, 0, 3){
            dp[i][j] = 1e9;
        }
    }
    for(int i = 1; i <= n; i++){
        if(s[i - 1] == 'J'){
            int id = lower_bound(J.begin(), J.end(), i) - J.begin();
            if(id >= k - 1){
                dp[i][0] = i - J[id - k + 1] + 1 - k;
            }
        }else if(s[i - 1] == 'O'){
            int id = lower_bound(O.begin(), O.end(), i) - O.begin();
            if(id >= k - 1){
                dp[i][1] = dp[O[id - k + 1] - 1][0] + (i - O[id - k + 1] + 1 - k); 
            }
        }else{
            int id = lower_bound(I.begin(), I.end(), i) - I.begin();
            if(id >= k - 1){
                dp[i][2] = dp[I[id - k + 1] - 1][1] + (i - I[id - k + 1] + 1 - k); 
            }
        }
        dp[i][0] = min(dp[i][0], dp[i - 1][0] + 1);
        dp[i][1] = min(dp[i][1], dp[i - 1][1] + 1);
        dp[i][2] = min(dp[i][2], dp[i - 1][2] + 1);
        
    }
    int res = 1e9;
    forr(i, 1, n + 1){
        res = min(res, dp[i][2]);
    }
    if(res == 1e9)cout << -1;
    else cout << res;
    return(0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 464 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 464 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 464 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 15 ms 3912 KB Output is correct
37 Correct 16 ms 4256 KB Output is correct
38 Correct 16 ms 3992 KB Output is correct
39 Correct 17 ms 4028 KB Output is correct
40 Correct 16 ms 4044 KB Output is correct
41 Correct 17 ms 4020 KB Output is correct
42 Correct 16 ms 4232 KB Output is correct
43 Correct 11 ms 2672 KB Output is correct
44 Correct 13 ms 3292 KB Output is correct
45 Correct 17 ms 4044 KB Output is correct
46 Correct 16 ms 4020 KB Output is correct
47 Correct 16 ms 4140 KB Output is correct
48 Correct 16 ms 4120 KB Output is correct
49 Correct 11 ms 2880 KB Output is correct
50 Correct 17 ms 4032 KB Output is correct
51 Correct 16 ms 4036 KB Output is correct
52 Correct 15 ms 3816 KB Output is correct
53 Correct 18 ms 4048 KB Output is correct
54 Correct 13 ms 3936 KB Output is correct
55 Correct 13 ms 3936 KB Output is correct
56 Correct 13 ms 3976 KB Output is correct