Submission #320951

# Submission time Handle Problem Language Result Execution time Memory
320951 2020-11-10T10:38:07 Z prarie Painting Walls (APIO20_paint) C++14
0 / 100
2 ms 3180 KB
#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]);
}

Compilation message

paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:25:22: warning: unused variable 'bef' [-Wunused-variable]
   25 |   int now = (i & 1), bef = (now ^ 1);
      |                      ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3052 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3180 KB Output is correct
2 Correct 2 ms 3052 KB Output is correct
3 Incorrect 2 ms 3052 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3180 KB Output is correct
2 Correct 2 ms 3052 KB Output is correct
3 Incorrect 2 ms 3052 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3180 KB Output is correct
2 Correct 2 ms 3052 KB Output is correct
3 Incorrect 2 ms 3052 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3180 KB Output is correct
2 Correct 2 ms 3052 KB Output is correct
3 Incorrect 2 ms 3052 KB Output isn't correct
4 Halted 0 ms 0 KB -