Submission #982692

#TimeUsernameProblemLanguageResultExecution timeMemory
982692stegatxins0Painting Walls (APIO20_paint)C++17
0 / 100
7 ms1884 KiB
#include <bits/stdc++.h> #include "paint.h" using namespace std; #ifdef DEBUG #include "debug.cpp" #else #define dbg(...) #define dbgarr(...) #endif // const int mxM = 50001; // int f[mxM]; // const int mxN = 1e5+1; int mp[mxN], ok[mxN]; bool like[mxN]; int minimumInstructions( int N, int M, int K, std::vector<int> C, std::vector<int> A, std::vector<std::vector<int>> B) { memset(mp,0,sizeof(mp)); memset(like,0,sizeof(like)); memset(ok,0,sizeof(ok)); // since each contarctor can only like one color, if no of contractor less than no of color, // if(M < K)return -1; // NOTE: B might have color not in C for(int i=0; i<M; i++){ for(int j=0; j<A[i]; j++){ like[B[i][j]] = 1; } } for(int i=1; i<=K; i++){ if(like[i] == 0 && binary_search(C.begin(), C.end(), i))return -1; } deque<int> q; int curunq = 0; for(int i=0; i<N; i++){ if(i >= M){ mp[C[i - M]]--; if(mp[C[i - M]] == 0){ curunq--; } q.pop_back(); } q.push_front(C[i]); mp[C[i]]++; if(mp[C[i]] <= 1){ curunq++; } if(curunq == M)ok[i] = 1; } dbgarr(ok,N); if(!ok[M-1] || !ok[N-1])return -1; int jump = 1; int p = M-1, tojump; while(p < N-1){ tojump = -1; for(int i=min(p+M,N-1); i>=p+1; i--){ if(ok[i]){ tojump = i; break; } } if(tojump == -1)return -1; jump++; p = tojump; // dbg(p, p+M); } return jump; }
#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...