# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
364835 | cpp219 | JJOOII 2 (JOI20_ho_t2) | C++14 | 2072 ms | 2100 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 int
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 2e5 + 3;
const ll inf = 1e9 + 7;
typedef pair<int,int> LL;
string s;
ll n,k;
vector<ll> J,O,I;
ll Forwardk(ll pos,vector<ll> v){
ll now = lower_bound(v.begin(),v.end(),pos) - v.begin();
now += k - 1;
if (now < v.size()) return v[now];
return -1;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define task "tst"
if (fopen(task".INP","r")){
freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
}
cin>>n>>k>>s; s = " " + s;
for (ll i = 1;i <= n;i++){
if (s[i] == 'J') J.push_back(i);
if (s[i] == 'O') O.push_back(i);
if (s[i] == 'I') I.push_back(i);
}
ll ans = inf;
for (ll i = 1;i <= n;i++){
if (s[i] != 'J') continue;
ll p = Forwardk(i,J); if (p == -1) break;
p = Forwardk(p,O); if (p == -1) break;
p = Forwardk(p,I); if (p == -1) break;
ans = min(ans,p - i + 1 - 3*k);
}
cout<<(ans == inf ? -1 : ans);
}
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... |