Submission #563457

#TimeUsernameProblemLanguageResultExecution timeMemory
5634578e7Painting Walls (APIO20_paint)C++17
0 / 100
19 ms13188 KiB
//Challenge: Accepted
#include "paint.h"
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 100005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
vector<int> f[maxn];
int n, m;
int zeros = 0;
int num[maxn];
int counter = 0;
void ch(int col, int ind, int d) {
	for (int i:f[col]) {
		int p = (i - ind + m)%m;
		if (num[p] == 0) zeros--;
		num[p] += d;
		if (num[p] == 0) zeros++;
	}
}
vector<int> pos;
bool poss[2 * maxn];
int to[2 * maxn];

int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B) {
	counter++;
	assert(counter == 1);
	m = M;
	n = N;
	for (int i = 0;i < M;i++) {
		for (int j = 0;j < A[i];j++) {
			f[B[i][j]].push_back(i);
		}
	}
	for (int i = 0;i < N;i++) {
		C.push_back(C[i]);
	}
	for (int i = 0;i < m;i++) num[i] = m;
	for (int i = 0;i < m;i++) ch(C[i], i, -1);
	for (int i = 0;i <= n - m;i++) {
		poss[i] = zeros > 0;
		if (poss[i]) pos.push_back(i);
		ch(C[i], i, 1);
		ch(C[i+m], i, -1);
	}
	int ps = pos.size();
	for (int i:pos) {
		int ind = upper_bound(pos.begin(), pos.end(), i+m) - pos.begin() - 1;
		to[i] = pos[ind];
	}
	int ret = 1<<30;
	int cur = 0, val = 0;
	while (cur < n - m) {
		if (to[cur] == cur) {
			break;
		}
		val++;
		cur = to[cur];
	}
	if (poss[0] && cur >= n - m) ret = val + 1;
	if (ret > n) return -1;
	return ret;
}

Compilation message (stderr)

paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:61:6: warning: unused variable 'ps' [-Wunused-variable]
   61 |  int ps = pos.size();
      |      ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...