| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 202301 | amoo_safar | JJOOII 2 (JOI20_ho_t2) | C++14 | 15 ms | 5884 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
const ll Mod = 1000000007LL;
const int N = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;
ll J[N], O[N], I[N];
vector<ll> v;
ll calc(ll x){
return I[O[J[x]]];
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n, k;
cin >> n >> k;
str s;
cin >> s;
J[n] = n;
O[n] = n;
I[n] = n;
v.clear();
for(int i = n - 1; i >= 0; i--){
if(s[i] == 'J') v.pb(i);
J[i] = (v.size() < k ? n : v[v.size() - k]);
}
v.clear();
for(int i = n - 1; i >= 0; i--){
if(s[i] == 'O') v.pb(i);
O[i] = (v.size() < k ? n : v[v.size() - k]);
}
v.clear();
for(int i = n - 1; i >= 0; i--){
if(s[i] == 'I') v.pb(i);
I[i] = (v.size() < k ? n : v[v.size() - k]);
}
if(calc(0) == n) return cout << "-1\n", 0;
ll ans = n;
for(int i = 0; i < n; i++){
if(calc(i) == n) break;
ans = min(ans, (calc(i) - i + 1) - 3*k);
}
cout << ans;
return 0;
}
/*
5
4 7 9 10 11 12
3 5 7 9 11
*/
컴파일 시 표준 에러 (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... | ||||
