This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Author: jainbot27
#pragma GCC optimize ("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ts to_string
#define ub upper_bound
#define lb lower_bound
#define ar array
#define FOR(x, y, z) for(int x = y; x < z; x++)
#define ROF(x, y, z) for(int x = y; x > z; x--)
#define all(x) x.begin(), x.end()
const char nl = '\n';
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using str = string;
using vpii = vector<pii>;
using vpll = vector<pll>;
str ts(char c) { return str(1,c); }
str ts(bool b) { return b ? "true" : "false"; }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
template<class A> str ts(complex<A> c) {
stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) {
str res = "{"; for(int i = 0;i < (int)v.size(); i++) res += char('0'+v[i]);
res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) {
str res = ""; for(int i = 0; i < b.size(); i++) res += char('0'+b[i]);
return res; }
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v) {
bool fst = 1; str res = "{";
for (const auto& x: v) {
if (!fst) res += ", ";
fst = 0; res += ts(x);
}
res += "}"; return res;
}
template<class A, class B> str ts(pair<A,B> p) {
return "("+ts(p.f)+", "+ts(p.s)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
cerr << ts(h); if (sizeof...(t)) cerr << ", ";
DBG(t...); }
#ifdef D
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif
const int N = 2e5 + 10;
int n, k;
string c;
vi pos[3];
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> k >> c;
for(int i = 0; i < n; i++){
if(c[i] == 'J'){
pos[0].pb(i);
}
else if(c[i] == 'O'){
pos[1].pb(i);
}
else{
pos[2].pb(i);
}
}
int amt = 0;
int ans = 2e9;
for(int i = 0; i < n; i++){
if(c[i] == 'J'){
amt++;
}
if(amt >= k){
int x = ub(pos[1].begin(), pos[1].end(), i) - pos[1].begin();
dbg(i , x);
if(x + k - 1< (int) pos[1].size()){
int defin = pos[1][x + k - 1];
int y = ub(all(pos[2]), defin) - pos[2].begin();
dbg(defin , y);
if(y + k - 1 < (int) pos[2].size()){
int defin2 = pos[2][y + k - 1];
int temp = (defin - pos[1][x] - (k-1)) + (defin2 - pos[2][y] - (k-1));
int pos3 = pos[0][amt - k];
dbg(defin2, temp, pos3);
temp += (i - pos3 - (k - 1)) + (pos[1][x] - i - 1) + (pos[2][y] - defin - 1);
ans = min(temp, ans);
}
}
}
}
if(ans == (int)2e9){
cout << -1 << nl;
}
else{
cout << ans << nl;
}
}
Compilation message (stderr)
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:94:14: warning: statement has no effect [-Wunused-value]
dbg(i , x);
^
ho_t2.cpp:98:19: warning: statement has no effect [-Wunused-value]
dbg(defin , y);
^
ho_t2.cpp:103:29: warning: statement has no effect [-Wunused-value]
dbg(defin2, temp, pos3);
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |