#include <bits/stdc++.h>
#include "paint.h"
using namespace std;
typedef bitset<50000> mask;
mask v[100000];
int lg[100001];
bool query(int l, int r, vector<vector<mask>> &raq)
{
int t = lg[r - l + 1];
return (raq[t][l] & raq[t][r - (1 << t) + 1]).count() > 0;
}
int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B)
{
lg[1] = 0;
for (int x = 2; x <= N; x++)
lg[x] = 1 + lg[x/2];
for (int i = 0; i < M; i++)
for (int c : B[i])
v[c][i] = 1;
mask ones;
for (int i = 0; i < M; i++) ones[i] = 1;
vector<vector<mask>> raq(20, vector<mask>(N));
for (int i = 0; i < N; i++)
raq[0][i] = ((v[C[i]] >> (i % M)) | (v[C[i]] << ((100000 * M - i) % M))) & ones;
for (int t = 1; (1 << t) <= N; t++)
for (int i = 0; i + (1 << t) - 1 < N; i++)
raq[t][i] = raq[t-1][i] & raq[t-1][i + (1 << (t-1))];
int ans = 0;
for (int i = 0, j; i < N; i = j)
{
mask cur = raq[0][i];
j = i + 1;
for (int t = lg[N]; t >= 0; t--)
if (j + (1 << t) - 1 < N && (cur & raq[t][j]).count() > 0)
j += (1 << t), cur &= raq[t][j];
j = min(j, i + M);
if (!query(j-M, j-1, raq))
return -1;
ans++;
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
480 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Runtime error |
65 ms |
64520 KB |
Execution killed with signal 11 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
480 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Runtime error |
65 ms |
64520 KB |
Execution killed with signal 11 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
480 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Runtime error |
65 ms |
64520 KB |
Execution killed with signal 11 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
480 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Runtime error |
65 ms |
64520 KB |
Execution killed with signal 11 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
480 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Runtime error |
65 ms |
64520 KB |
Execution killed with signal 11 |
8 |
Halted |
0 ms |
0 KB |
- |