# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
401928 | faresbasbs | Painting Walls (APIO20_paint) | C++14 | 2 ms | 2636 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;
vector<int> vals[100001];
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 += 1){
for(auto j : B[i]){
vals[j].push_back(i);
}
}
vector<pair<int,int>> q,q2;
for(int i : vals[c[0]]){
q.push_back({i,1});
}
vector<int> all;
for(int i = 1 ; i < n ; i += 1){
q2.clear();
for(auto j : q){
if(j.second == m){
continue;
}
if(*lower_bound(vals[c[i]].begin(),vals[c[i]].end(),(j.first+1)%m) == (j.first+1)%m){
q2.push_back({(j.first+1)%m,j.second+1});
if(j.second == m-1){
all.push_back(i-m+1);
}
}
}
for(auto j : vals[c[i]]){
q2.push_back({j,1});
}
swap(q,q2);
}
if(all.size() == 0 || all[0] != 0){
return -1;
}
int pre = 0 , mx = 0 , cnt = 1;
for(int i = 0 ; i < all.size() ; i += 1){
if(pre+m >= all[i]){
mx = all[i];
continue;
}
if(mx == pre){
return -1;
}
cnt += 1 , pre = mx;
i -= 1;
}
if(pre+m == n){
return cnt;
}
pre = mx , cnt += 1;
if(pre+m == n){
return cnt;
}
return -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... |