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;
ostream& operator<<(ostream &out, string str) {
for(char c : str) out << c;
return out;
}
template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
return out << "(" << p.first << ", " << p.second << ")";
}
template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
out << "{";
for(auto it = a.begin(); it != a.end(); it = next(it))
out << (it != a.begin() ? ", " : "") << *it;
return out << "}";
}
void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
cerr << a << ", ";
dump(x...);
}
#ifdef DEBUG
# define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
# define debug(...) false
#endif
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second
template<class T> int size(T && a) { return a.size(); }
using LL = long long;
using PII = pair<int, int>;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k;
string str;
cin >> n >> k >> str;
vector<int> a, b, c;
int A = -1e9, B = -1e9, ans = 1e9;
REP(i, n) {
if(str[i] == 'J') {
a.emplace_back(i);
if(size(a) >= k)
A = a[size(a) - k];
}
else if(str[i] == 'O') {
b.emplace_back(A);
if(size(b) >= k)
B = b[size(b) - k];
}
else if(str[i] == 'I') {
c.emplace_back(B);
if(size(c) >= k) {
int C = c[size(c) - k];
ans = min(ans, i - C + 1 - 3 * k);
}
}
}
if(ans > n) ans = -1;
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |