#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
#include "paint.h"
int minimumInstructions(int N, int M, int K, vi C, vi A, vector<vi> B) {
vi use(K, -1);
for (int i = 0; i < M; i++) {
for (int j = 0; j < A[i]; j++) {
use[B[i][j]] = i;
}
}
vector<bool> cfill(N - M + 1, false);
for (int i = 0; i < N - M + 1; i++) {
// try all rotations
if (use[C[i]] == -1)
continue;
int j = use[C[i]];
// cout<<i<<": "<<j<<endl;
bool works = true;
for (int k = 0; k < M; k++) {
// use (k+j) mod M
if (use[C[i + k]] != ((k + j) % M)) {
works = false;
break;
}
}
if (works)
cfill[i] = true;
}
/* cout<<"cfill: ";
for (bool b : cfill)
cout<<b<<" ";
cout<<endl;*/
set<int> good;
for (int i = 0; i < N - M + 1; i++) {
if (cfill[i])
good.insert(i);
}
good.insert(-M);
good.insert(N);
int curr = -M;
int total = 0;
while (curr < N) {
auto it = good.lower_bound(curr + M + 1);
if (it == good.begin())
return -1;
int newc = *(--it);
if (newc == curr)
return -1;
curr = newc;
total++;
}
total--;
return total;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
860 KB |
Output is correct |
14 |
Correct |
1 ms |
860 KB |
Output is correct |
15 |
Correct |
1 ms |
860 KB |
Output is correct |
16 |
Correct |
1 ms |
860 KB |
Output is correct |
17 |
Correct |
1 ms |
860 KB |
Output is correct |
18 |
Correct |
1 ms |
860 KB |
Output is correct |
19 |
Correct |
0 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
0 ms |
604 KB |
Output is correct |
22 |
Correct |
7 ms |
1540 KB |
Output is correct |
23 |
Correct |
7 ms |
1628 KB |
Output is correct |
24 |
Correct |
7 ms |
1624 KB |
Output is correct |
25 |
Correct |
5 ms |
1368 KB |
Output is correct |
26 |
Correct |
5 ms |
1368 KB |
Output is correct |
27 |
Correct |
3 ms |
860 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
2 ms |
348 KB |
Output is correct |
31 |
Correct |
76 ms |
2048 KB |
Output is correct |
32 |
Correct |
75 ms |
1872 KB |
Output is correct |
33 |
Correct |
76 ms |
2032 KB |
Output is correct |
34 |
Correct |
75 ms |
1872 KB |
Output is correct |
35 |
Correct |
78 ms |
1876 KB |
Output is correct |
36 |
Correct |
77 ms |
2032 KB |
Output is correct |
37 |
Correct |
12 ms |
1856 KB |
Output is correct |
38 |
Correct |
10 ms |
1884 KB |
Output is correct |
39 |
Correct |
8 ms |
1884 KB |
Output is correct |
40 |
Correct |
23 ms |
5212 KB |
Output is correct |
41 |
Correct |
15 ms |
3420 KB |
Output is correct |
42 |
Correct |
14 ms |
3420 KB |
Output is correct |
43 |
Correct |
7 ms |
1112 KB |
Output is correct |
44 |
Correct |
5 ms |
860 KB |
Output is correct |
45 |
Correct |
6 ms |
1116 KB |
Output is correct |
46 |
Execution timed out |
1573 ms |
8068 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
860 KB |
Output is correct |
14 |
Correct |
1 ms |
860 KB |
Output is correct |
15 |
Correct |
1 ms |
860 KB |
Output is correct |
16 |
Correct |
1 ms |
860 KB |
Output is correct |
17 |
Correct |
1 ms |
860 KB |
Output is correct |
18 |
Correct |
1 ms |
860 KB |
Output is correct |
19 |
Correct |
0 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
0 ms |
604 KB |
Output is correct |
22 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |