Submission #802694

#TimeUsernameProblemLanguageResultExecution timeMemory
802694radaiosm7Painting Walls (APIO20_paint)C++11
28 / 100
1571 ms7800 KiB
#include "paint.h" #include <bits/stdc++.h> using namespace std; #define X first #define Y second int n, m, x, y, l, s, i, mn; vector<pair<int, int> > segs; bool ok; stack<pair<int, int> > S; bool cmp(const pair<int, int>& a, const pair<int, int>& b) { if (a.Y == b.Y) return a.X < b.X; return a.Y < b.Y; } int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int> > B) { for (y=0; y <= N-M; ++y) { for (x=0; x < M; ++x) { ok = true; for (l=0; l < M && ok; ++l) ok &= binary_search(B[(x+l)%M].begin(), B[(x+l)%M].end(), C[y+l]); if (!ok) continue; segs.push_back(make_pair(y, y+M-1)); break; } } sort(segs.begin(), segs.end(), cmp); s = (int)segs.size(); if (s == 0) return -1; mn = segs[0].X; S.push(segs[0]); for (i=1; i < s; ++i) { if (segs[i].X > S.top().Y+1) continue; if (segs[i].Y == S.top().Y) continue; while (!S.empty() && S.top().X >= segs[i].X) S.pop(); if (!S.empty()) S.push(make_pair(S.top().Y+1, segs[i].Y)); else S.push(segs[i]); mn = min(mn, segs[i].X); } if (mn > 0 || S.top().Y < N-1) return -1; return (int)S.size(); }
#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...