# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
347985 | arnold518 | Painting Walls (APIO20_paint) | C++14 | 558 ms | 15724 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;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e5;
const int MAXM = 5e4;
const int MAXK = 1e5;
int N, M, K;
int C[MAXN+10];
vector<int> B[MAXK+10];
int dp[2][MAXM+10], chk[MAXN+10];
int dp2[MAXN+10];
int minimumInstructions(int _N, int _M, int _K, vector<int> _C, vector<int> _A, vector<vector<int>> _B)
{
N=_N; M=_M; K=_K;
for(int i=0; i<N; i++) C[i]=_C[i];
for(int i=0; i<M; i++)
{
for(auto it : _B[i])
{
B[it].push_back(i);
}
}
for(int i=0; i<N; i++)
{
if(i>=2)
{
for(auto it : B[C[i-2]])
{
dp[i&1][it]=0;
}
}
for(auto it : B[C[i]])
{
dp[i&1][it]=1;
if(i!=0 && dp[i-1&1][(it+M-1)%M])
{
dp[i&1][it]=dp[i-1&1][(it+M-1)%M]+1;
}
if(dp[i&1][it]>=M)
{
chk[i+1]=1;
}
}
}
deque<int> DQ;
DQ.push_back(0);
for(int i=1; i<=N; i++)
{
dp2[i]=987654321;
if(!chk[i]) continue;
while(!DQ.empty() && DQ.front()<i-M) DQ.pop_front();
if(DQ.empty()) continue;
dp2[i]=dp2[DQ.front()]+1;
while(!DQ.empty() && dp2[DQ.back()]>=dp2[i]) DQ.pop_back();
DQ.push_back(i);
//printf("%d ", dp2[i]);
}
if(dp2[N]==987654321) return -1;
return dp2[N];
}
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... |