이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define vec vector
#define int long long
#define inf 1e18
const int mod = 998244353 , men = 1e9 + 7;
/*
▀█████████▄ ▄█ ▄█ ▄████████ ▄█ ▄████████ ▄██████▄ ████████▄ ▄████████ ▄████████
███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ▀███ ███ ███ ███ ███
███ ███ ███▌ ███ ███ ███ ███ ███ █▀ ███ ███ ███ ███ ███ █▀ ███ ███
▄███▄▄▄██▀ ███▌ ███ ███ ███ ███ ███ ███ ███ ███ ███ ▄███▄▄▄ ▄███▄▄▄▄██▀
▀▀███▀▀▀██▄ ███▌ ███ ▀███████████ ███ ███ ███ ███ ███ ███ ▀▀███▀▀▀ ▀▀███▀▀▀▀▀
███ ██▄ ███ ███ ███ ███ ███ ███ █▄ ███ ███ ███ ███ ███ █▄ ▀███████████
███ ███ ███ ███▌ ▄ ███ ███ ███▌ ▄ ███ ███ ███ ███ ███ ▄███ ███ ███ ███ ███
▄█████████▀ █▀ █████▄▄██ ███ █▀ █████▄▄██ ████████▀ ▀██████▀ ████████▀ ██████████ ███ ███
▀ ▀ ███ ███
*/
template<typename _T>
bool chmin(_T &a, const _T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename _T>
bool chmax(_T &a, const _T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
double dist(double x1 , double y1 , double x2 , double y2){
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
inline void io(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
inline void solve(){
int n , k;
cin >> n >> k;
string s;
cin >> s;
int ans = 1e9;
int r = 0;
auto tuura = [&](int l){
string c = "";
int jj = k , oo = k , ii = k;
for (int i = l; i < n; i++){
if (jj > 0 and s[i] == 'J')
c += s[i] , jj--;
if (jj == 0 && oo > 0 && s[i] == 'O')
c += s[i] , oo--;
if (jj == 0 && oo == 0 && ii > 0 && s[i] == 'I')
c += s[i] , ii--;
r = i;
if (ii <= 0)break;
}
if ((int)c.size() != k * 3 || jj > 0 || oo > 0 || ii > 0)
return false;
for (int i = 0; i < k; i++)
if (c[i] != 'J')
return false;
for (int i = k; i < 2 * k; i++)
if (c[i] != 'O')
return false;
for (int i = 2 * k; i < 3 * k; i++)
if (c[i] != 'I')
return false;
return true;
};
for (int l = 0; l + k * 3 - 1 < n; l++){
//~ for (int r = l + k * 3 - 1; r < n; r++){
if (/*(r - l + 1) >= k * 3 && */tuura(l))
chmin(ans , (r - l + 1) - 3 * k);
//~ }
}
cout << (ans != 1e9 ? ans : -1) << "\n";
}
signed main() {
io();
int t = 1;
//~ cin >> t;
while(t--)
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |