# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
375333 | astoria | Painting Walls (APIO20_paint) | C++14 | 543 ms | 524292 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
#include "paint.h"
using namespace std;
int minimumInstructions(int N, int M, int K, std::vector<int> C, std::vector<int> A, std::vector<std::vector<int>> B){
vector<int> f[K+5]; //for the colour i, who can do?
for(int i=0; i<M; i++){
for(int j=0; j<A[i]; j++){
int col = B[i][j];
f[col].push_back(i);
}
}
int lng[N+5][M+5];
memset(lng,-1,sizeof(lng));
for(int j : f[C[0]]) lng[0][j]=1;
for(int j=0; j<M; j++){
lng[0][j]=max(lng[0][j],0);
}
for(int i=1; i<N; i++){
for(int j : f[C[i]]){
lng[i][j] = 1;
int lst = j-1; if(lst<0) lst+=M;
lng[i][j] += lng[i-1][lst];
}
for(int j=0; j<M; j++) lng[i][j]=max(lng[i][j],0);
}
for(int i=0; i<N; i++){
sort(lng[i],lng[i]+M);
reverse(lng[i],lng[i]+M);
}
int dp[N+5];
multiset<int> mns; mns.insert(0);
for(int i=0; i<N; i++){
if(lng[i][0]<M) dp[i]=1e9;
else dp[i]=(*mns.begin())+1;
mns.insert(dp[i]);
if(mns.size()>M&&i>=M) mns.erase(mns.find(dp[i-M]));
else if(mns.size()>M) mns.erase(0);
}
if(dp[N-1]>=1e6) return -1;
return dp[N-1];
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |