#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define sz(x) int((x).size())
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
template<class X, class Y>
inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);}
template<class X, class Y>
inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Random(int l, int r) {
return uniform_int_distribution<int>(l, r)(rng);
}
const int MAXN = 100005;
const int MAXM = 50004;
vector<int> B[MAXM], C[MAXN];
int colNeed[MAXN], sum[MAXN], f[MAXN], nArr, mArr, numCol;
int sub1(void) {
for (int i = 1; i <= nArr; ++i) {
if(sz(C[colNeed[i]]) == 0)
return -1;
f[i] = C[colNeed[i]][0];
sum[i] = sum[i - 1] + (i > 1 && (f[i - 1] + 1) % mArr == f[i]);
}
int res(0), maxi(1), lastok(-mArr);
for (int i = 1; i <= nArr; ++i) {
if(sum[i + mArr - 1] - sum[i] == mArr - 1 && (f[i + mArr - 1] + 1) % mArr == f[i])
lastok = i;
if(i == maxi) {
if(lastok + mArr <= i)
return -1;
maxi = lastok + mArr;
++res;
}
}
return res;
}
int minimumInstructions(int _N, int _M, int _K, vector<int> _C, vector<int> _A, vector<vector<int>> _B) {
nArr = _N, mArr = _M, numCol = _K;
for (int i = 1; i <= nArr; ++i) {
colNeed[i] = _C[i - 1];
C[i].clear();
}
int maxf(0);
for (int i = 0; i < mArr; ++i) {
int szlike(_A[i]);
B[i].clear();
for (int j = 0; j < szlike; ++j) {
B[i].push_back(_B[i][j]);
C[_B[i][j]].push_back(i);
maxf = max(maxf, sz(C[_B[i][j]]));
}
}
if(maxf <= 1)
return sub1();
return -1;
}
#ifdef Nhoksocqt1
int main(void) {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define TASK "paint"
if(fopen(TASK".inp", "r")) {
freopen(TASK".inp", "r", stdin);
freopen(TASK".out", "w", stdout);
}
vector<int> _A, _C;
vector<vector<int>> _B;
int _N, _M, _K;
cin >> _N >> _M >> _K;
_C.resize(_N);
for (int i = 0; i < _N; ++i)
cin >> _C[i];
_A.resize(_M), _B.resize(_M);
for (int i = 0; i < _M; ++i) {
cin >> _A[i];
_B[i].resize(_A[i]);
for (int j = 0; j < _A[i]; ++j)
cin >> _B[i][j];
}
int ans = minimumInstructions(_N, _M, _K, _C, _A, _B);
cout << "ANSWER: " << ans << '\n';
return 0;
}
#endif // Nhoksocqt1
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
6 ms |
4968 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
5208 KB |
Output is correct |
10 |
Correct |
1 ms |
4956 KB |
Output is correct |
11 |
Correct |
1 ms |
4956 KB |
Output is correct |
12 |
Correct |
1 ms |
4956 KB |
Output is correct |
13 |
Correct |
2 ms |
4956 KB |
Output is correct |
14 |
Correct |
1 ms |
4968 KB |
Output is correct |
15 |
Correct |
1 ms |
4952 KB |
Output is correct |
16 |
Correct |
2 ms |
5012 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4980 KB |
Output is correct |
20 |
Correct |
2 ms |
4952 KB |
Output is correct |
21 |
Correct |
2 ms |
4956 KB |
Output is correct |
22 |
Correct |
16 ms |
9972 KB |
Output is correct |
23 |
Correct |
15 ms |
9816 KB |
Output is correct |
24 |
Correct |
24 ms |
9820 KB |
Output is correct |
25 |
Correct |
4 ms |
5236 KB |
Output is correct |
26 |
Correct |
3 ms |
5208 KB |
Output is correct |
27 |
Correct |
3 ms |
5212 KB |
Output is correct |
28 |
Correct |
3 ms |
5212 KB |
Output is correct |
29 |
Correct |
3 ms |
5212 KB |
Output is correct |
30 |
Correct |
3 ms |
5212 KB |
Output is correct |
31 |
Correct |
7 ms |
6488 KB |
Output is correct |
32 |
Correct |
6 ms |
6492 KB |
Output is correct |
33 |
Correct |
7 ms |
6492 KB |
Output is correct |
34 |
Correct |
7 ms |
6516 KB |
Output is correct |
35 |
Correct |
7 ms |
6492 KB |
Output is correct |
36 |
Correct |
6 ms |
6492 KB |
Output is correct |
37 |
Correct |
18 ms |
10332 KB |
Output is correct |
38 |
Correct |
17 ms |
10332 KB |
Output is correct |
39 |
Correct |
18 ms |
10332 KB |
Output is correct |
40 |
Correct |
8 ms |
5980 KB |
Output is correct |
41 |
Correct |
6 ms |
5468 KB |
Output is correct |
42 |
Correct |
8 ms |
6068 KB |
Output is correct |
43 |
Correct |
6 ms |
5724 KB |
Output is correct |
44 |
Correct |
6 ms |
5724 KB |
Output is correct |
45 |
Correct |
8 ms |
6076 KB |
Output is correct |
46 |
Correct |
33 ms |
16716 KB |
Output is correct |
47 |
Correct |
25 ms |
11608 KB |
Output is correct |
48 |
Correct |
25 ms |
14684 KB |
Output is correct |
49 |
Correct |
29 ms |
14940 KB |
Output is correct |
50 |
Correct |
29 ms |
14352 KB |
Output is correct |
51 |
Correct |
23 ms |
11724 KB |
Output is correct |
52 |
Correct |
9 ms |
5976 KB |
Output is correct |
53 |
Correct |
9 ms |
5976 KB |
Output is correct |
54 |
Correct |
9 ms |
5980 KB |
Output is correct |
55 |
Correct |
9 ms |
6076 KB |
Output is correct |
56 |
Correct |
8 ms |
5980 KB |
Output is correct |
57 |
Correct |
8 ms |
5980 KB |
Output is correct |
58 |
Correct |
38 ms |
17496 KB |
Output is correct |
59 |
Correct |
38 ms |
17472 KB |
Output is correct |
60 |
Correct |
37 ms |
17492 KB |
Output is correct |
61 |
Correct |
36 ms |
17492 KB |
Output is correct |
62 |
Correct |
37 ms |
17632 KB |
Output is correct |
63 |
Correct |
36 ms |
17664 KB |
Output is correct |
64 |
Correct |
37 ms |
16724 KB |
Output is correct |
65 |
Correct |
37 ms |
16728 KB |
Output is correct |
66 |
Correct |
42 ms |
16604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
6 ms |
4968 KB |
Output is correct |
7 |
Correct |
2 ms |
4956 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
5208 KB |
Output is correct |
10 |
Correct |
1 ms |
4956 KB |
Output is correct |
11 |
Correct |
1 ms |
4956 KB |
Output is correct |
12 |
Correct |
1 ms |
4956 KB |
Output is correct |
13 |
Correct |
2 ms |
4956 KB |
Output is correct |
14 |
Correct |
1 ms |
4968 KB |
Output is correct |
15 |
Correct |
1 ms |
4952 KB |
Output is correct |
16 |
Correct |
2 ms |
5012 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4980 KB |
Output is correct |
20 |
Correct |
2 ms |
4952 KB |
Output is correct |
21 |
Correct |
2 ms |
4956 KB |
Output is correct |
22 |
Incorrect |
1 ms |
4964 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4964 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4964 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4964 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |