Submission #678666

# Submission time Handle Problem Language Result Execution time Memory
678666 2023-01-06T10:11:09 Z Dan4Life Painting Walls (APIO20_paint) C++17
0 / 100
1 ms 2644 KB
#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define SZ(a) (int)a.size()
using vi = vector<int>;
const int maxn = (int)1e5+10;
const int maxm = (int)5e4+10;

const int INF = (int)1e9;

int n, m, k, c[maxn];
set<int> S[maxm];

bool works(int x, int y){
	if(y>n-m) return false;
	for(int i = 0; i < n; i++, x++, y++, x-=(x>=m?m:0))
		if(!S[x].count(c[y])) return false;
	return true;
}

int minimumInstructions(int N, int M, int K, vi C, vi A, vector<vi> B) {
	n = N, m = M, k = K;
	for(int i = 0; i < n; i++) c[i] = C[i];
	for(int i = 0; i < m; i++)
		for(auto u : B[i]) S[i].insert(u);
	if(m==1){
		for(int i = 0; i < n; i++) 
			if(!S[0].count(c[i])) return -1;
		return 1;
	}
	int ans = 0;
	for(int i = 0; i+m <= n; i+=m){
		bool ok = false;
		for(int x = 0; x < m; x++){
			if(!works(x, i)) continue;
			ok = true;
		}
		if(!ok) return -1; 
		ans++;
	}
	return ans;
}

/*
8 3 5
3 3 1 3 4 4 2 2
3 0 1 2
2 2 3
2 3 4
Ans=3

5 4 4
1 0 1 2 2
2 0 1
1 1
1 2
1 3


5 3 4
1 0 2 2 3  
Ans=-1
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Incorrect 1 ms 2644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Incorrect 1 ms 2644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Incorrect 1 ms 2644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Incorrect 1 ms 2644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Incorrect 1 ms 2644 KB Output isn't correct
3 Halted 0 ms 0 KB -