| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 701988 | huomark1001 | JJOOII 2 (JOI20_ho_t2) | C++17 | 1 ms | 340 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>
#include<random>
using namespace std;
template<typename T> void _do(T x){cerr<<x<<"\n";}
template<typename T,typename ...U> void _do(T x,U ...y){cerr<<x<<", ";_do(y...);}
#define dbg(...) cerr<<#__VA_ARGS__<<" = ";_do(__VA_ARGS__);
#define float double
#define ss(n) fixed<<setprecision(n)
#define ll long long
#define int ll
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define rep(i,a) for(int i=1;i<=a;i++)
#define rep0(i,a) for(int i=0;i<a;i++)
#define F first
#define S second
#define uni(a) a.resize(distance(a.begin(),unique(a.begin(),a.end())));
#define unisort(a) sort(a.begin(),a.end()); uni(a);
ll gcd(ll a,ll b){if(b==0) return a; return gcd(b,a%b);}
const ld pi=3.14159265358979323846264338327950288419716939931;
const int lar=3e18;
const int mol1=1e9+7;
const int mol2=998244353;
const int MX=3e5;
void solve()
{
int n,k;
cin>>n>>k;
string a;
cin>>a;
vector<int>a1,a2,a3;
rep0(i,a.size()){
if(a[i]=='J') a1.pb(i);
if(a[i]=='O') a2.pb(i);
if(a[i]=='I') a3.pb(i);
}
int ans=lar;
bool ok=0;
int l1=0,l2=0,l3=0;
while(a1.size()-1-l1+1>=k){
int bb=l1+k-1;
int pos=a1[bb];
while(l2+k-1<=a2.size()-1&&a2[l2]<pos){
l2++;
}
int ppos=a2[l2+k-1];
while(l3+k-1<=a3.size()-1&&a3[l3]<ppos) l3++;
if(a2[l2]>pos&&a3[l3]>ppos){
ok=1;
ans=min(ans,a3[l3+k-1]-a1[l1]+1-k*3);
}
l1++;
}
if(ok) cout<<ans<<"\n";
else cout<<-1<<"\n";
}
signed main()
{
IO
solve();
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... | ||||
