# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
984492 | Mr_Ph | Painting Walls (APIO20_paint) | C++17 | 1 ms | 348 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 "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
int minimumInstructions(int n,int m,int k,vector<int>c,vector<int>a,vector<vector<int>>b)
{
vector<vector<int>>mp(k);
for(int i=0;i<m;i++)
{
for(int j=0;j<b[i].size();j++)
mp[b[i][j]].push_back(i);
}
vector<int>arr(k);
vector<int>temparr(k);
vector<int>valid(n);
for(int i=0;i<n;i++)
{
for(int j=0;j<mp[c[i]].size();j++)
{
int x=mp[c[i]][j]-1;
if(x<0)x=m-1;
temparr[mp[c[i]][j]]=min(arr[x]+1,m);
}
if(i)
{
for(int j=0;j<mp[c[i-1]].size();j++)
arr[mp[c[i-1]][j]]=0;
}
for(int j=0;j<mp[c[i]].size();j++)
{
arr[mp[c[i]][j]]=temparr[mp[c[i]][j]];
if(arr[mp[c[i]][j]]==m){
// cout<<i<<endl;
assert((i-m+1)>=0);
valid[i-m+1]=1;
}
temparr[mp[c[i]][j]]=0;
}
}
// for(int i=0;i<n;i++)cout<<valid[i]<<" ";
// cout<<endl;
vector<int>dp(n);
for(int i=0;i<n;i++)dp[i]=1e9;
priority_queue<pair<int,int>>pq;
pq.push({0,0});
for(int i=0;i<n;i++)
{
while(pq.size()&&pq.top().second<(i-1))
pq.pop();
if(!pq.size())break;
// cout<<i<<" ";
int x=-pq.top().first;
if(valid[i])
{
dp[i+m-1]=min(dp[i+m-1],x+1);
pq.push({-dp[i+m-1],i+m-1});
}
}
if(dp[n-1]>=1e9)return -1;
else 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... |