# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
221871 | davooddkareshki | JJOOII 2 (JOI20_ho_t2) | C++17 | 23 ms | 9540 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>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define int long long
const int maxn = 5e5+10;
const int inf = 2e9+10;
string s;
int n, k;
vector<int> ve[26];
int lst[maxn];
int lj[maxn], lo[maxn], li[maxn];
signed main()
{
cin>> n >> k >> s;
s = "*" + s;
// cout<< s <<" ";
// cout<< s[n] <<" ";
ll ans = inf;
for(int i = 1; i <= n; i++)
{
int x = s[i]-'A';
// cout<< x <<" ";
ve[x].push_back(i);
// cout<< x <<" ";
if(ve[x].size() >= k)
{
// cout<< ve[x].size() - k <<" ";
lst[i] = ve[x][ve[x].size()-k];
}
if(s[i] == 'J') lj[i] = i;
else lj[i] = lj[i-1];
if(s[i] == 'O') lo[i] = i;
else lo[i] = lo[i-1];
if(s[i] == 'I') li[i] = i;
else li[i] = li[i-1];
if(s[i] == 'I')
{
int x = lst[i];
//cout<< x <<" ";
x = lo[x];
//cout<< x <<" ";
x = lst[x];
//cout<< x <<" ";
x = lj[x];
// cout<< x <<" ";
x = lst[x];
// cout<< x <<" ";
// cout<<
if(x > 0)
ans = min(ans, i-x+1);
}
}
if(ans == inf)
return cout<< -1, 0;
cout<< ans - 3 * k;
}
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... |