#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int md(int x, int y) {
return (x % y + y) % y;
}
int minimumInstructions (int n, int m, int k, std::vector<int> a, std::vector<int> SZ, std::vector<std::vector<int>> b) {
vector<vector<int>> f(k);
for (int i = 0; i < m; i++) for (int j : b[i]) {
f[j].push_back(i);
// cout << j << ' ' << i << '\n';
}
deque<pair<int, int>> dq;
vector<int> cnt(m, 0);
vector<int> dp(n, 0);
dq.push_back({0, -1});
for (int i = 0; i < n; i++) {
vector<int> goat;
if (i >= m) for (int j : f[a[i - m]]) --cnt[md(j - i + m, m)];
for (int j : f[a[i]]) {
cnt[md(j - i, m)]++;
if (cnt[md(j - i, m)] == m) goat.push_back(md(j - i, m));
}
if (!goat.empty()) {
// cout << i << '\n';
// for (int j : goat) cout << j << ' ';
// cout << '\n';
while (!dq.empty() && dq.front().second < i - m) dq.pop_front();
if (i >= m - 1) dp[i] = dq.front().first + 1;
else dp[i] = inf;
// older time ones are better
while (!dq.empty() && dq.back().first > dp[i]) dq.pop_back();
dq.push_back({dp[i], i});
} else dp[i] = inf;
// for (int j = 0; j < m; j++) cout << cnt[j] << ' ';
// cout << '\n';
// cout << "dp " << i << " = " << dp[i] << '\n';
}
if (dp[n - 1] == inf) return -1;
return dp[n - 1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |