# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
724262 |
2023-04-15T02:19:39 Z |
Cookie |
JJOOII 2 (JOI20_ho_t2) |
C++14 |
|
1 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]);
dp[i][1] = min(dp[i][1], dp[i - 1][1]);
dp[i][2] = min(dp[i][2], dp[i - 1][2]);
}
cout << ((dp[n][2] == 1e9) ? -1 : dp[n][2]);
return(0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |