답안 #832382

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
832382 2023-08-21T09:51:25 Z Antekb 벽 칠하기 (APIO20_paint) C++17
0 / 100
3 ms 4948 KB
#include<bits/stdc++.h>
#include "paint.h"
#define st first
#define nd second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define pp pop_back
#define mp make_pair
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vii = vector<pii>;
void debug(){cerr<<"\n";}
template<typename H, typename... T>
void debug(H h, T... t){
    cerr<<h;
    if(sizeof...(t)){
        cerr<<", ";
    }
    debug(t...);
}
#define deb(x...) cerr<<#x<<" = ";debug(x);

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N=1e5+5;
vi kto[N], dp[N];
int czy[N], opt[N];

int minimumInstructions(int n, int m, int k, std::vector<int> C,
	std::vector<int> A, std::vector<std::vector<int>> B) {
	for(int i=0; i<m; i++){
		for(int j:B[i]){
			kto[j].pb(i);
		}
	}
	for(int i=0; i<n; i++){
		if(!kto[C[i]].size())return 0;
	}
	for(int i=0; i<n; i++){
		dp[i].resize(kto[C[i]].size(), 1);
		int wsk=0;
		if(i){
			if(kto[C[i]][0]==0 && kto[C[i-1]].back()==m-1){
				dp[i][0]=dp[i-1].back()+1;
			}
			for(int j=0; j<dp[i].size(); j++){
				while(wsk!=dp[i-1].size() && kto[C[i-1]][wsk]+1<kto[C[i]][j]){
					wsk++;
				}
				if(wsk!=dp[i-1].size() && kto[C[i-1]][wsk]+1==kto[C[i]][j]){
					//deb(i, j);
					dp[i][j]=dp[i-1][wsk]+1;
				}
			}
		}
		//deb(i);
		for(int j:dp[i]){
			//deb(j);
			if(j>=m)czy[i+1]=1;
		}
	}
	multiset<int> S;
	S.insert(0);
	for(int i=1; i<=n; i++){
		opt[i]=1e9;
		if(czy[i]){
			opt[i]=1+*S.begin();
		}
		//deb(i, opt[i]);
		S.insert(opt[i]);
		if(i>=m)S.erase(S.find(opt[i-m]));
	}
	if(opt[n]==1e9)opt[n]=-1;
	return opt[n];
}

Compilation message

paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:48:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |    for(int j=0; j<dp[i].size(); j++){
      |                 ~^~~~~~~~~~~~~
paint.cpp:49:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     while(wsk!=dp[i-1].size() && kto[C[i-1]][wsk]+1<kto[C[i]][j]){
      |           ~~~^~~~~~~~~~~~~~~~
paint.cpp:52:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     if(wsk!=dp[i-1].size() && kto[C[i-1]][wsk]+1==kto[C[i]][j]){
      |        ~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Incorrect 2 ms 4948 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Incorrect 2 ms 4948 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Incorrect 2 ms 4948 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Incorrect 2 ms 4948 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Incorrect 2 ms 4948 KB Output isn't correct
4 Halted 0 ms 0 KB -