Submission #597408

#TimeUsernameProblemLanguageResultExecution timeMemory
597408OzyPainting Walls (APIO20_paint)C++17
100 / 100
240 ms16212 KiB
#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 100000 #define MK 100000 lli n,m,k,res,pos,mejor,dif,a,last, par; //valores de 0 a m vector< vector <pair<int, int> > > lejos(2, vector<pair<int, int> >(MAX + 2)); vector<int> contratistas[MK]; lli top[MAX+2]; //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) { contratistas[B[i][j]].push_back(i); } } repa(i,n-1,0) { top[i] = 0; for(auto cont : contratistas[C[i]]) { int sigcont = (cont < m - 1) ? cont + 1 : 0; int v; if (lejos[par ^ 1][sigcont].first == i + 1) v = min(m, lejos[par ^ 1][sigcont].second + 1); else v = 1; lejos[par][cont] = {i, v}; top[i] = max(top[i], v); } par ^= 1; } if (top[0] < m) return -1; pos = m; last = 0; res = 1; rep(i,1,n-1) { if (top[i] == m) last = i; if (i == pos) { pos = last + m; res++; } } if (pos < n) return -1; else return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...