# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
400045 | SavicS | JJOOII 2 (JOI20_ho_t2) | C++14 | 11 ms | 3192 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 <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define fb(i,b,a) for(int i=b;i>=a;i--)
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 200005;
const int inf = 1e9 + 5;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k) print the k-th smallest number in os(0-based)
int n, K;
string s;
int ptr[4];
int pref[maxn][3];
int f(char C){
if(C == 'J')return 1;
if(C == 'O')return 2;
if(C == 'I')return 3;
assert(false);
}
int main()
{
ios::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
cin >> n >> K >> s;
s = ' ' + s;
ff(i,1,n){
ff(j,1,3)pref[i][j] = pref[i - 1][j];
pref[i][f(s[i])] += 1;
}
int rez = inf;
for(ptr[0] = 0; ptr[0] <= n; ptr[0] += 1){
ff(i,1,3){
while (ptr[i] < ptr[i - 1] || (ptr[i] <= n && pref[ptr[i]][i] - pref[ptr[i - 1]][i] < K)){
ptr[i]++;
}
}
bool ok = 1;
ff(i,1,3)ok &= (ptr[i] <= n && pref[ptr[i]][i] - pref[ptr[i - 1]][i] >= K);
if(ok)rez = min(rez, ptr[3] - ptr[0] - 3 * K);
}
cout << (rez == inf ? -1 : rez) << endl;
return 0;
}
/**
9 3
JJJOOOIII
// probati bojenje sahovski ili slicno
**/
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... |