Submission #1106254

#TimeUsernameProblemLanguageResultExecution timeMemory
1106254vladiliusPainting Walls (APIO20_paint)C++17
28 / 100
1551 ms8272 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; #define pb push_back #define ff first #define ss second const int inf = 3e5; struct ST{ vector<int> a; int n; ST(int ns){ n = ns; a.resize(n + 1); } void upd(int p, int x){ p++; a[p] += x; } int get(){ int out = 0; for (int i = 1; i <= n; i++){ out = max(out, a[i]); } return out; } }; int minimumInstructions(int n, int m, int k, vector<int> x, vector<int> A, vector<vector<int>> B){ vector<int> d[k]; for (int i = 0; i < m; i++){ for (int j: B[i]){ d[j].pb(i); } } vector<bool> gd(n); int i = 0, j = 0; ST T(inf); while (i < n){ while (j < n){ for (int f: d[x[j]]){ T.upd(f - j + n, 1); T.upd(f - j + (m + n), 1); } if (T.get() != (j - i + 1)){ for (int f: d[x[j]]){ T.upd(f - j + n, -1); T.upd(f - j + (m + n), -1); } break; } j++; } for (int f = i; f <= j - m; f++) gd[f] = 1; for (int f: d[x[i]]){ T.upd(f - i + n, -1); T.upd(f - i + (m + n), -1); } i++; } int mx = -1, t = -1, out = 0; for (int i = 0; i < n; i++){ if (gd[i]) t = i; if (i == (mx + 1)){ if (t == -1) return -1; mx = t + m - 1; t = -1; out++; } } return out; }
#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...