| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 201034 | HellAngel | JJOOII 2 (JOI20_ho_t2) | C++14 | 94 ms | 48516 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200007;
string s;
int nxt[20][maxn][3], a[maxn], n, k, ans;
void Jump(int &pos, int type, int cnt)
{
for(int i = 19; i >= 0; i--)
{
if(cnt >= (1 << i))
{
cnt -= (1 << i);
pos = nxt[i][pos][type];
}
}
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin);
cin >> n >> k >> s;
ans = n + 1;
for(int i = 1; i <= n; i++)
{
if(s[i - 1] == 'J') a[i] = 0;
if(s[i - 1] == 'O') a[i] = 1;
if(s[i - 1] == 'I') a[i] = 2;
}
nxt[0][n + 1][0] = nxt[0][n + 1][1] = nxt[0][n + 1][2] = n + 1;
for(int i = n; i >= 1; i--)
{
for(int j = 0; j < 3; j++) nxt[0][i][j] = nxt[0][i + 1][j];
if(i == n) continue;
nxt[0][i][a[i + 1]] = i + 1;
}
for(int len = 1; len < 20; len++)
{
for(int i = 1; i <= n + 1; i++)
{
for(int j = 0; j < 3; j++)
{
int nlen = (1 << len);
if(i + nlen - 1 > n) nxt[len][i][j] = 1 + n;
nxt[len][i][j] = nxt[len - 1][nxt[len - 1][i][j]][j];
}
}
}
for(int i = 1; i <= n; i++)
{
int cur = i;
if(a[cur] != 0) continue;
Jump(cur, 0, k - 1);
Jump(cur, 1, k);
Jump(cur, 2, k);
if(cur <= n)
{
ans = min(ans, cur - i + 1 - k * 3);
}
}
if(ans == n + 1) cout << -1;
else cout << ans;
}
컴파일 시 표준 에러 (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... | ||||
