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;
#define lli int
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repa(i,a,b) for (int i = (a); i >= (b); i--)
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define MAX 20000
lli n,m,k,res,pos,mejor,dif,a;
//valores de 0 a m
lli lejos[MAX+2][2002];
lli tabla[2002][2002];
//checar memoria
int minimumInstructions(int N, int M, int K, std::vector<int> C,std::vector<int> A, std::vector<std::vector<int>> B) {
n = N;
m = M;
k = K;
rep(i,0,m-1) {
rep(j,0,A[i]-1) {
tabla[i][B[i][j]] = 1;
}
}
repa(i,n-1,0) {
rep(j,0,m-1) {
if (tabla[j][C[i]] == 1) {
lejos[i][j] = lejos[i+1][(j+1)%m] + 1;
if (lejos[i][j] > m) lejos[i][j] = m;
}
else lejos[i][j] = 0;
}
}
pos = 0;
res = 0;
while (pos < n) {
mejor = 0;
rep(i,0,m-1) {
if (lejos[pos][i] <= mejor) continue;
dif = m - lejos[pos][i];
a = m + i - dif;
a %= m;
if ( (pos-dif) < 0) continue;
if (lejos[pos-dif][a] == m) mejor = lejos[pos][i];
}
if (mejor == 0) break;
else {
pos += mejor;
res++;
}
}
if (pos < n) return -1;
else return res;
}
# | 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... |