# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
576568 | ParsaEs | Painting Walls (APIO20_paint) | C++14 | 1055 ms | 13008 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.
//InTheNameOfGOD
//PRS;)
#include<bits/stdc++.h>
#include "paint.h"
#define rep(i, l, r) for(ll i = l; i < r; i++)
#define pb push_back
#define X first
#define Y second
typedef int ll;
using namespace std;
typedef pair<ll, ll> pi;
constexpr ll inf = 1e9;
ll minimumInstructions(ll N, ll M, ll K, vector<ll> C, vector<ll> A, vector<vector<ll>> B)
{
vector<ll> c[K + 1];
rep(i, 0, B.size()) for(ll j : B[i]) c[j].pb(i);
vector<ll> dp(N + 1, inf), cnt(M + 1, 0);
deque<pi> q;
ll gn = 0;
rep(i, 0, N)
{
if(M <= i) for(ll j : c[C[i - M]]) gn -= (cnt[(N + j - i) % M]-- == M);
for(ll j : c[C[i]]) gn += (++cnt[(N + j - i) % M] == M);
if(gn)
{
if(i == M - 1) dp[i] = 1;
else
{
while(!q.empty() && q.front().Y < i - M) q.pop_front();
if(!q.empty()) dp[i] = q.front().X + 1;
}
while(!q.empty() && q.back().X >= dp[i]) q.pop_back();
q.pb({dp[i], i});
}
}
return (dp[N - 1] >= inf ? -1 : 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... |