이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 && !dq.empty()) dp[i] = min(inf, 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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |