Submission #1176167

#TimeUsernameProblemLanguageResultExecution timeMemory
1176167tkm_algorithms벽 칠하기 (APIO20_paint)C++20
0 / 100
0 ms324 KiB
/**
*    In the name of Allah
*    We are nothing and you're everything
**/
#include <bits/stdc++.h>
#include "paint.h"
using namespace std;
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
//#define int ll
const char nl = '\n';
//const int inf = 1e18+1;
const int N = 2e4;
const int M = 2e3;
int dp[N][M];

int minimumInstructions(int n, int m, int k, vector<int> c, vector<int> a, vector<vector<int>> b) {
	
	
	map<pair<int, int>, int> mp;
	for (int i = 0; i < sz(a); ++i) {
		for (auto j: b[i])mp[{i, j}] = 1;
	}
	for (int i = n-1; i >= 0; --i) {
		for (int j = 0; j < m; ++j)
			if (mp[{j, c[i]}])dp[i][j] = max(dp[i][j], dp[i+1][(j+1)%m]+1);
	}
	
	vector<int> p(n+1);
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
			if (dp[i][j] >= m) {
				p[i] = 1;
				break;
			}
			
	int start = 0;
	if (p[0] == 0)return -1;
	
	vector<int> vis(n);
	int ans;
	while (start < n) {
		if (p[start] == 0)--start;
		if (p[start] == 1 && vis[start] == 1) {
			return -1;
		} else {
			ans += 1;
			vis[start] = 1;
			start += m;
		}
	}
	
	if (start >= n)return ans;
}


	//ios::sync_with_stdio(false);
	//cin.tie(nullptr);

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:55:1: warning: control reaches end of non-void function [-Wreturn-type]
   55 | }
      | ^
#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...