# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
320951 | prarie | 벽 칠하기 (APIO20_paint) | C++14 | 2 ms | 3180 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> col[100005]; // 색 k 를 좋아하는 일꾼의 집합
bool wall[100005]; // 벽 i 를 칠할 수 있는가?
int dp[100005];
// 벽 i 를 칠할 수 있을 때
// [0 ... i] 까지 칠하는 최소 횟수
// dp[i] = min(dp[
int minimumInstructions(
int N, int M, int K, std::vector<int> C,
std::vector<int> A, std::vector<std::vector<int>> B) {
for (int i = 0; i < M; i++) {
for (auto &m : B[i]) col[m].push_back(i);
}
vector<int> con(M);
for (auto &n : col[C[0]]) con[n] = 1;
for (int i = 1; i < N; i++) {
vector<int> next_con(M);
int now = (i & 1), bef = (now ^ 1);
for (auto &n : col[C[i]]) {
next_con[n] = con[(n - 1 + M) % M] + 1;
if (next_con[n] == M) {
wall[i] = true;
next_con[n] = M - 1;
}
}
con = next_con;
}
memset(dp, -0x2f, sizeof dp);
deque<pair<int, int>> dq;
if (wall[M - 1]) {
dp[M - 1] = 1;
dq.emplace_back(M - 1, 1);
}
for (int i = M; i < N; i++) {
if (!wall[i]) continue;
while (dq.size() && dq.back().first < i - M) dq.pop_back();
if (dq.empty()) break;
dp[i] = dq.back().second + 1;
while (dq.size() && dq.front().second >= dp[i]) dq.pop_front();
dq.emplace_front(i, dp[i]);
}
return (dp[N - 1] < 0 ? -1 : dp[N - 1]);
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |