Submission #810206

#TimeUsernameProblemLanguageResultExecution timeMemory
810206boyliguanhanPainting Walls (APIO20_paint)C++17
63 / 100
1593 ms365412 KiB
#include "paint.h" #include <bits/stdc++.h> using namespace std; unordered_map<int, int> lseg[200100]; vector<int> liked_by[200100]; int dp[200100]{}, valid_i[200100]{}; int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B) { for(int i = 0; i < N; i++) lseg[i].clear(),dp[i]=valid_i[i]=0; for(int i = 0; i < K; i++) liked_by[i].clear(); multiset<int> st; for(int i = 0; i < M; i++) for(int color: B[i]) liked_by[color].push_back(i); for(int i = N; i--;) { for(auto j: liked_by[C[i]]) { lseg[i][j] = 1+lseg[i+1][(j+1)%M]; if(lseg[i][j]>=M) valid_i[i]=1; } lseg[i+1].clear(); } for(int i = 0; i < M; i++) st.insert(0); for(int i = N; i--;) { dp[i]=1e9; if(valid_i[i]) dp[i] = 1+*st.begin(); st.insert(dp[i]); st.erase(st.find(dp[i+M])); } return (dp[0]<1e9?dp[0]:-1); }
#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...