# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
296093 | Alexa2001 | Painting Walls (APIO20_paint) | C++17 | 1079 ms | 12984 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 Nmax = 1e5 + 5;
vector<int> good[Nmax];
int nr = 0, n, m;
int shift[Nmax];
bool ok[Nmax];
int dp[Nmax];
void upd(int pos, int add)
{
nr -= (shift[pos] == m);
shift[pos] += add;
nr += (shift[pos] == m);
}
int minimumInstructions(int N, int M, int k, vector<int> c, vector<int> A, vector<vector<int>> B)
{
n = N; m = M;
int i, j;
for(i=0; i<m; ++i)
for(auto it : B[i])
good[it].push_back(i);
for(i=0; i<m; ++i)
for(auto it : good[c[i]])
upd((it - i%m + m) % m, +1);
if(nr) ok[m-1] = 1;
for(i=m; i<n; ++i)
{
for(auto it : good[c[i]])
upd((it - i%m + m) % m, +1);
for(auto it : good[c[i-m]])
upd((it - i%m + m) % m, -1);
if(nr) ok[i] = 1;
}
if(!ok[m-1] || !ok[n-1]) return -1;
deque<int> dq;
dq.push_back(m-1);
dp[m-1] = 1;
for(i=m; i<n; ++i)
{
if(!ok[i]) continue;
while(dq.size() && dq.front() < i-m) dq.pop_front();
if(dq.empty()) return -1;
dp[i] = dp[dq.front()] + 1;
dq.push_back(i);
}
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... |