# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
553298 | FatihSolak | Painting Walls (APIO20_paint) | C++17 | 2 ms | 2644 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>
#define N 100005
#define K 705
using namespace std;
vector<int> col[N];
int dp[N][K];
int ok[N];
int minimumInstructions(int n, int m, int k, vector<int> c,vector<int> a, vector<vector<int>> b) {
for(int i = 0;i<m;i++){
for(int j = 0;j<a[i];j++){
col[b[i][j]].push_back(i);
}
}
for(int i = 0;i<n;i++){
if(col[c[i]].size() == 0)
return -1;
}
/*
for(int i = 0;i<k;i++){
for(auto u:col[i]){
cout << u << " ";
}
cout << endl;
}*/
for(int i = 0;i<col[c[0]].size();i++){
dp[0][i] = 1;
if(dp[0][i] == m)
ok[0 - m + 1] = 1;
}
for(int i = 1;i<n;i++){
int pt = 0;
for(int j = 0;j<col[c[i]].size();j++){
dp[i][j] = 1;
while(pt + 1 < col[c[i-1]].size() && col[c[i-1]][pt] + 1 < col[c[i]][j]){
pt++;
}
//cout << "hey" << pt << endl;
if(col[c[i-1]][pt] + 1 == col[c[i]][j]){
dp[i][j] = max(dp[i][j],min(m, dp[i-1][pt]+1));
}
if(col[c[i]][j] == 0 && col[c[i-1]].back() == m-1){
dp[i][j] = max(dp[i][j],min(m, dp[i-1][col[c[i-1]].size()-1]+1));
}
//cout << dp[i][j] << " ";
if(dp[i][j] == m)
ok[i - m +1] = 1;
}
//cout << endl;
}
/*
for(int i = 0;i<n;i++){
cout << ok[i] << " ";
}
cout << endl;*/
int cnt = 0;
int last = -1;
int maxi = 0;
while(maxi < n){
int val = maxi;
for(int i = last+1;i<=maxi;i++){
if(ok[i]){
val = max(val,i + m);
}
}
if(val == maxi){
return -1;
}
cnt++;
last = maxi+1;
maxi = val;
}
return cnt;
}
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... |