답안 #1069365

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1069365 2024-08-21T20:26:14 Z pawned 벽 칠하기 (APIO20_paint) C++17
0 / 100
0 ms 348 KB
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

#include "paint.h"

int minimumInstructions(int N, int M, int K, vi C, vi A, vector<vi> B) {
	vi use(K, -1);
	for (int i = 0; i < M; i++) {
		for (int j = 0; j < A[i]; j++) {
			use[B[i][j]] = i;
		}
	}
	vi valr(N, -1);
	for (int i = 0; i < N; i++) {
		valr[i] = use[C[i]];
	}
/*	cout<<"valr: ";
	for (int x : valr)
		cout<<x<<" ";
	cout<<endl;*/
	vi diff(N - 1, 0);
	vi is1(N - 1, 0);	// 1 if diff[i] is 1; 0 otherwise
	for (int i = 0; i < N - 1; i++) {
		diff[i] = valr[i + 1] - valr[i];
		diff[i] %= M;
		diff[i] += M;
		diff[i] %= M;
		if (diff[i] == 1)
			is1[i] = 1;
	}
/*	cout<<"diff: ";
	for (int x : diff)
		cout<<x<<" ";
	cout<<endl;*/
	vi pfs(N, 0);
	pfs[0] = 0;
	for (int i = 1; i < N; i++) {
		pfs[i] = pfs[i - 1] + is1[i - 1];
	}
	vector<bool> cfill(N - M + 1, false);
	for (int i = 0; i < N - M + 1; i++) {
		if (pfs[i + M - 1] - pfs[i] == M - 1)
			cfill[i] = true;
	}
/*	cout<<"cfill: ";
	for (bool b : cfill)
		cout<<b<<" ";
	cout<<endl;*/
	set<int> good;
	for (int i = 0; i < N - M + 1; i++) {
		if (cfill[i])
			good.insert(i);
	}
	good.insert(-M);
	good.insert(N);
	int curr = -M;
	int total = 0;
	while (curr < N) {
		auto it = good.lower_bound(curr + M + 1);
		if (it == good.begin())
			return -1;
		int newc = *(--it);
		if (newc == curr)
			return -1;
		curr = newc;
		total++;
	}
	total--;
	return total;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -