Submission #718697

# Submission time Handle Problem Language Result Execution time Memory
718697 2023-04-04T14:25:54 Z Radin_Zahedi2 Painting Walls (APIO20_paint) C++17
0 / 100
1 ms 212 KB
#include "paint.h"
#include<bits/stdc++.h>
//#include <vector>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (int)x.size()
#define endl '\n'

int minimumInstructions(
    int N, int M, int K, std::vector<int> C,
    std::vector<int> A, std::vector<std::vector<int>> B) {

	
	vector<int> have[K];
	for (int i = 0; i < M; i++) {
		for (int j = 0; j < A[i]; j++) {
			have[B[i][j]].pb(i);
		}
	}

	
	bool can[N];
	fill(can + 0, can + N, false);

	int best[M];
	fill(best + 0, best + M, 0);
	vector<int> pre;
	for (int i = 0; i < N; i++) {
		vector<int> now;

		for (auto x : have[C[i]]) {
			int pre = x - 1;
			if (pre == -1) {
				pre = M - 1;
			}

			now.pb(min(best[pre] + 1, M));
		}

		for (auto x : now) {
			if (x >= M) {
				can[i] = true;
			}
		}

		for (auto x : pre) {
			best[x] = 0;
		}
		for (int j = 0; j < sz(have[C[i]]); j++) {
			best[have[C[i]][j]] = now[j];
		}

		pre = now;
	}


	int dp[N];
	deque<pair<int, int>> q;
	q.push_back(mp(-1, 0));
	for (int i = 0; i < N; i++) {
		if (!can[i]) {
			dp[i] = -1;
			continue;
		}


		while (!q.empty()) {
			if (i - q.front().fi <= M) {
				break;
			}

			q.pop_front();
		}

		if (q.empty()) {
			dp[i] = -1;
			continue;
		}

		dp[i] = q.front().se + 1;

		while (!q.empty()) {
			if (q.back().se < dp[i]) {
				break;
			}

			q.pop_back();
		}
		q.push_back(mp(i, dp[i]));
	}
		

	return dp[N - 1];
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Incorrect 1 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Incorrect 1 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Incorrect 1 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Incorrect 1 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Incorrect 1 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -