# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
576505 | Arnch | Painting Walls (APIO20_paint) | C++17 | 755 ms | 13296 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 Sz(x) x.size()
using namespace std;
const int N = 1e5 + 10;
int dp[N], delta[N], cnt[N];
bool mark[N];
vector<int> vc[N];
int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B) {
for(int i = 0; i < Sz(B); i++) {
for(auto j : B[i]) {
vc[j].push_back(i);
}
}
for(int i = 0; i < Sz(A); i++) delta[i] = -1, dp[i] = 0;
vector<int> can, nc;
for(int i = 0; i < Sz(C); i++) {
can.clear(), nc.clear();
if(Sz(vc[C[i]]) == 0) {
return -1;
}
for(auto j : vc[C[i]]) {
if(delta[(j - 1 + M) % M] == i - 1) {
can.push_back(j);
}
else {
nc.push_back(j);
}
}
for(auto j : can) {
delta[j] = i, cnt[j] = dp[(j - 1 + M) % M];
if(cnt[j] < M) cnt[j]++;
}
for(auto j : can) {
dp[j] = cnt[j];
if(dp[j] == M) mark[i] = 1;
}
for(auto j : nc) {
delta[j] = i, dp[j] = 1;
if(dp[j] == M) mark[i] = 1;
}
}
/*for(int i = 0; i < Sz(C); i++) {
cout<<mark[i] <<" ";
}
cout<<endl;*/
int ptr = Sz(C) - 1, ans = 1;
if(mark[ptr] == 0) {
return -1;
}
while(ptr >= M) {
ans++;
bool F = 0;
for(int i = max(M - 1, ptr - M); i < ptr; i++) {
if(mark[i]) {
F = 1;
ptr = i; break;
}
}
if(!F) return -1;
}
return ans;
}
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... |