Submission #333435

#TimeUsernameProblemLanguageResultExecution timeMemory
333435534351Painting Walls (APIO20_paint)C++17
0 / 100
2 ms2668 KiB
#include "paint.h" #include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> using namespace std; // using namespace __gnu_pbds; // template<class T> // using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<class T, class U> void ckmin(T &a, U b) { if (a > b) a = b; } template<class T, class U> void ckmax(T &a, U b) { if (a < b) a = b; } #define MP make_pair #define PB push_back #define LB lower_bound #define UB upper_bound #define fi first #define se second #define SZ(x) ((int) (x).size()) #define ALL(x) (x).begin(), (x).end() #define FOR(i, a, b) for (auto i = (a); i < (b); i++) #define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--) typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpi; typedef vector<pll> vpl; const int MAXN = 100013; const int INF = 1e9 + 7; int N, M, K; //N numbers, M contractors, K colors, each colors supports blah contractors, sum(blah^2) is small int arr[MAXN]; vi ok[MAXN]; int dp[MAXN]; bitset<MAXN> chk; multiset<int> dps; int ans; int getval(int x) { x %= M; if (x < 0) x += M; return x; } int minimumInstructions(int n, int m, int k, vi C, vi A, vector<vi> B) { N = n; M = m; K = k; copy(ALL(C), arr); FOR(i, 0, SZ(A)) { FOR(j, 0, A[i]) { ok[B[i][j]].PB(i); } } FOR(i, 0, N) { for (int x : ok[arr[i]]) { // cerr << x << ' ' << getval(x - i) << endl; dp[getval(x - i)]++; } if (i >= M) { for (int x : ok[arr[i - M]]) { dp[getval(x - i)]--; } } for (int x : ok[arr[i]]) { if (dp[getval(x - i)] == M) { chk[i] = true; // cerr << "CHK " << i << endl; } } } if (!chk[M - 1]) { return -1; } fill(dp, dp + M, INF); dp[M - 1] = 1; FOR(i, 0, M) { dps.insert(dp[i]); } FOR(i, M, N) { dp[i] = (chk[i] ? *dps.begin() + 1 : INF); dps.insert(dp[i]); dps.erase(dps.find(dp[i - M])); } ans = dp[N - 1]; if (ans == INF) ans = -1; return ans; //now find min taht's checkable. // FOR(i, 0, n) // { // for (int x : ok[arr[i]]) // { // cerr << x << ' '; // } // cerr << endl; // } }
#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...