# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
434680 | dqhungdl | Painting Walls (APIO20_paint) | C++17 | 17 ms | 22604 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 "paint.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX=1e5+5;
int _N,_M;
vector<int> companies[MAX],g[MAX],f[MAX];
vector<bool> mark[MAX];
int dfs(int i,int j) {
if(i==_N-1)
return _N-1;
if(mark[i][j])
return f[i][j];
mark[i][j]=true;
int pos=lower_bound(g[i+1].begin(),g[i+1].end(),(g[i][j]+1)%_M)-g[i+1].begin();
if(g[i+1][pos]==(g[i][j]+1)%_M)
return f[i][j]=dfs(i+1,pos);
return f[i][j]=i;
}
int minimumInstructions(
int N, int M, int K, std::vector<int> C,
std::vector<int> A, std::vector<std::vector<int>> B) {
_N=N,_M=M;
for(int i=0;i<M;i++)
for(int j=0;j<A[i];j++)
companies[B[i][j]].push_back(i);
for(int i=0;i<N;i++) {
g[i]=companies[C[i]];
mark[i].resize(g[i].size());
f[i].resize(g[i].size());
}
vector<bool> canStart(N);
for(int i=0;i<N;i++)
for(int j=0;j<g[i].size();j++) {
int far=dfs(i,j);
if(far-i+1>=M)
canStart[i]=true;
}
int cur=-1,lastPos=0,rs=0;
while(lastPos<N) {
int found=-1;
for(int i=lastPos;i>cur;i--)
if(canStart[i]) {
found=i;
break;
}
if(found==-1)
return -1;
lastPos=found+M;
cur=found;
rs++;
}
return rs;
}
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... |