//from duckindog wth depression
#include<bits/stdc++.h>
using namespace std;
//#define LOCAL
#ifndef LOCAL
#include "paint.h"
#endif // LOCAL
const int N = 500 + 10;
int f[N];
int minimumInstructions(int n, int m, int k, vector<int> C, vector<int> A, vector<vector<int>> B) {
memset(f, 63, sizeof f);
f[0] = 0;
for (int l = 0; l < n - m + 1; ++l) {
int r = l + m - 1;
bool pass = 0;
for (int x = 0; x < m; ++x) {
bool good = 1;
for (int i = l; i <= r; ++i) {
int y = (i - l + x) % m;
if (!binary_search(B[y].begin(), B[y].end(), C[i])) good = 0;
}
pass |= good;
}
if (pass) {
r += 1;
l += 1;
for (int i = l - 1; i < r; ++i)
f[r] = min(f[r], f[i] + 1);
}
}
return f[n] > 1e9 ? -1 : f[n];
}
#ifdef LOCAL
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
if (fopen("duck.inp", "r")) {
freopen("duck.inp", "r", stdin);
freopen("duck.out", "w", stdout);
}
int n, m, k; cin >> n >> m >> k;
vector<int> C, A;
vector<vector<int>> B;
for (int i = 1; i <= n; ++i) {
int x; cin >> x;
C.push_back(x);
}
for (int i = 1; i <= m; ++i) {
int a; cin >> a; A.push_back(a);
vector<int> vt;
for (int j = 1; j <= a; ++j) {
int x; cin >> x;
vt.push_back(x);
}
sort(vt.begin(), vt.end());
B.push_back(vt);
}
cout << minimumInstructions(n, m, k, C, A, B);
}
#endif // LOCAL
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |