# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
201034 | HellAngel | JJOOII 2 (JOI20_ho_t2) | C++14 | 94 ms | 48516 KiB |
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;
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;
}
Compilation message (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... |