| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1353401 | dex111222333444555 | JJOOII 2 (JOI20_ho_t2) | C++20 | 6 ms | 2064 KiB |
#include <bits/stdc++.h>
#define all(v) begin(v), end(v)
#define ii pair<int, int>
#define fi first
#define se second
#define siz(v) (int)(v).size()
#define lli pair<long long, int>
#define dbg(x) "[" #x " = " << x << "]"
#define BIT(x, i) (((x) >> (i)) & 1)
#define MASK(i) (1LL << (i))
#define left __left
#define right __right
using namespace std;
bool M1;
const long long inf = 1e18 + 123;
const int mod = 1e9 + 7, infINT = 1e9 + 1321, LOG = 32;
template<class X, class Y> bool minimize(X &x, const Y &y){return x > y ? x = y, 1: 0;}
template<class X, class Y> bool maximize(X &x, const Y &y){return x < y ? x = y, 1: 0;}
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
ll ran(ll l, ll r){
return uniform_int_distribution<ll>(l, r)(rd);
}
void add(int &a, const int &b){
a += b;
if (a >= mod) a -= mod;
}
void sub(int &a, const int &b){
a -= b;
if (a < 0) a += mod;
}
int mul(const int &a, const int &b){
return 1LL * a * 1LL * b % mod;
}
int bin_pow(int a, long long k){
int res = 1;
while(k){
if (k & 1) res = mul(res, a);
k >>= 1; a = mul(a, a);
}
return res;
}
const int MAXN = 2e5 + 5;
int lenS, target;
string s;
vector<int > pos[3];
void input(){
cin >> lenS >> target;
cin >> s;
s = '_' + s;
}
int id(const char &c){
if (c == 'J') return 0;
if (c == 'O') return 1;
return 2;
}
void solve(){
for(int i = 1; i <= lenS; i++){
pos[id(s[i])].push_back(i);
}
int j, k, res = lenS + 1;
for(int i = 0; i + target - 1 < siz(pos[0]); i++){
vector<int >::iterator it;
j = upper_bound(all(pos[1]), pos[0][i + target - 1]) - begin(pos[1]);
if (j + target - 1 >= siz(pos[1])) break;
k = upper_bound(all(pos[2]), pos[1][j + target - 1]) - begin(pos[2]);
if (k + target - 1 >= siz(pos[2])) break;
res = min((pos[2][k + target - 1] - pos[0][i] + 1) - (3 * target), res);
}
cout << (res <= lenS ? res: -1) << '\n';
cerr << (res <= lenS ? res: -1) << '\n';
}
bool M2;
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define task "test"
if (fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
input();
solve();
cerr << (&M2 - &M1) / 1048576 << " mb\n";
cerr << (1.0 * clock()) / CLOCKS_PER_SEC << ".s\n";
}
컴파일 시 표준 에러 (stderr) 메시지
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
