이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "paint.h"
#ifndef EVAL
#include "grader.cpp"
#endif
#include <bits/stdc++.h>
#define pii pair<int, int>
#define F first
#define S second
using namespace std;
int minimumInstructions(
int N, int M, int K, vector<int> C,
vector<int> A, vector<vector<int>> B)
{
auto match = [&](int i, int j)
{
auto iter = lower_bound(B[j].begin(), B[j].end(), C[i]);
if(iter != B[j].end() && *iter == C[i])
return 1;
return 0;
};
vector<int> cover(N, 0), dp(N, 0);
for (int x = 0; x < M; x++)
{
int cnt = 0;
for (int y = 0; y < M; y++)
cnt += match(y, (x + y) % M);
for (int y = 0; y < N - M; y++)
{
cover[y] |= (cnt == M);
cnt -= match(y, (x + y) % M);
cnt += match(y + M, (x + y + M) % M);
}
cover[N - M] |= (cnt == M);
}
for (int i = 0; i < N; i++)
{
dp[i] = (cover[i] ? i : (i ? dp[i - 1] : 0));
}
int cur = 0, ans = 0;
for (int i = 0; i < N; i++)
if (cur < N)
cur = max(cur, dp[cur] + M), ans++;
return (cur < N ? -1 : ans);
}
# | 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... |