답안 #724265

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
724265 2023-04-15T02:23:38 Z Cookie JJOOII 2 (JOI20_ho_t2) C++14
0 / 100
0 ms 212 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[n][2]);
    }
    if(res == 1e9)cout << -1;
    else cout << res;
    return(0);
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -