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;
const int INF = INT_MAX / 2;
const int M_MAX = 2000;
mt19937 rng(time(0));
int rngSeg (int l, int len)
{
return l + rng() % len;
}
int minimumInstructions(int N, int M, int K, vector <int> C, vector <int> A, vector <vector <int>> B)
{
vector <bitset <M_MAX>> likers (K);
for(int i = 0; i < M; i++)
for(int j = 0; j < A[i]; j++)
likers[B[i][j]][i] = true;
function <bool (int, int)> likes = [&] (int worker, int color)
{
int l = 0, r = A[worker];
while(l < r)
{
int mid = (l + r) / 2;
if(B[worker][mid] < color)
l = mid + 1;
else
r = mid;
}
return (l < A[worker] && B[worker][l] == color);
};
vector <bool> possible (N - M + 1);
for(int l = 0; l + M - 1 < N; l++)
{
bitset <M_MAX> ok;
ok.set();
for(int i = 0; i < M; i++)
{
ok &= likers[C[l + i]];
bool aux = ok[M - 1];
ok <<= 1;
ok[0] = aux;
possible[l] = ok.any();
if(possible[l] == false)
break;
}
}
vector <int> minPref (N, INF);
deque <int> dq;
minPref[M - 1] = INF;
if(possible[0] == true)
minPref[M - 1] = 1;
for(int i = M; i < N; i++)
{
if(dq.empty() == false && dq.front() < i - M)
dq.pop_front();
while(dq.empty() == false && minPref[i - 1] <= minPref[dq.back()])
dq.pop_back();
dq.push_back(i - 1);
if(possible[i - M + 1] == true)
{
if(minPref[dq.front()] != INF)
minPref[i] = minPref[dq.front()] + 1;
}
}
if(minPref[N - 1] == INF)
return -1;
return minPref[N - 1];
}
# | 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... |