# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
568134 | Ronin13 | JJOOII 2 (JOI20_ho_t2) | C++14 | 0 ms | 212 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
const int inf = 1e9 + 1;
int main(){
int n, k; cin >> n >> k;
string s; cin >> s;
vector <int> j;
int ansp[n + 1];
for(int i = 0; i < s.size(); i++){
if(s[i] == 'O'){
if(j.size() < k){
ansp[i] = inf;
}
else{
int x = j[j.size() - 1];
int y = j[j.size() - k];
ansp[i] = x - y + 1 - k;
}
}
else if(s[i] == 'J')j.pb(i);
}
vector <int> i;
int anss[n + 1];
for(int p = s.size() - 1; p >= 0; p--){
if(s[p] == 'O'){
if(i.size() < k) anss[p] = inf;
else{
int x = i[i.size() - 1];
int y = i[i.size() - k];
anss[p] = y - x + 1 - k;
}
}
else{if(s[p] == 'I') i.pb(p);}
}
vector <int> os;
for(int p = 0; p < s.size(); p++) if(s[p] == 'O') os.pb(p);
int ans = inf;
for(int i = 0; i <= (int)os.size() - k; i++){
int x = os[i];
int y = os[i + k - 1];
ans = min(ans, ansp[x] + anss[y] + y - x + 1 - k);
}
if(ans == inf) cout << -1;
else cout << ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |