Submission #735499

#TimeUsernameProblemLanguageResultExecution timeMemory
735499keisuke6Painting Walls (APIO20_paint)C++14
15 / 100
1566 ms5724 KiB
#include "paint.h" #include <iostream> #include <vector> #include <map> #include <set> #include <queue> using namespace std; int minimumInstructions(int N, int M, int K, vector<int> C,vector<int> A, vector<vector<int>> B){ vector<vector<int>> G(N+1); vector<set<int>> S(M); for(int i=0;i<M;i++)for(int x:B[i]) S[i].insert(x); for(int i=0;i<=N-M;i++){ bool ok = false; for(int j=0;j<M;j++){ if(ok) break; bool now = true; for(int k=i;k<i+M;k++){ if(!S[(j+k-i)%M].count(C[k])) now = false; } if(now) ok = true; } if(ok){ for(int j=i+1;j<=i+M;j++) G[i].push_back(j); } } queue<int> q; q.push(0); vector<int> dist(N+1,1e9); dist[0] = 0; while(!q.empty()){ int pos = q.front(); q.pop(); for(int x:G[pos]){ if(dist[x] != 1e9) continue; dist[x] = dist[pos] + 1; q.push(x); } } if(dist[N] == 1e9) return -1; else return dist[N]; }
#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...