Submission #1176248

#TimeUsernameProblemLanguageResultExecution timeMemory
1176248tkm_algorithmsPainting Walls (APIO20_paint)C++20
100 / 100
259 ms14072 KiB
/** * In the name of Allah * We are nothing and you're everything **/ #include <bits/stdc++.h> //#include "paint.h" using namespace std; #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() typedef long long ll; //#define int ll const char nl = '\n'; //const int inf = 1e18+1; const int N = 1e5; const int M = 5e4; int dp[2][M+2]; int upd[2][M+2]; int minimumInstructions(int n, int m, int k, vector<int> c, vector<int> a, vector<vector<int>> b) { ios::sync_with_stdio(false); cin.tie(nullptr); vector<int> mp[k+1]; //map<int, int> mp; for (int i = 0; i < sz(a); ++i) { for (auto j: b[i])mp[j].push_back(i); } //c[i+1] degislimi b[j+1] int x; vector<int> p(n+1); int use = 1; for (int i = n-1; i >= 0; --i) { use ^= 1; for (int j = 0; j < sz(mp[c[i]]); ++j) { x = mp[c[i]][j]; upd[use][x] = i; if (upd[use^1][(x+1)%m] != i+1 || i == n-1) { dp[use][x] = 1; } else { dp[use][x] = dp[use^1][(x+1)%m]+1; } if (dp[use][x] >= m)p[i] = 1; } } int start = 0; if (p[0] == 0)return -1; vector<int> vis(n); int ans = 0; while (start < n) { while (p[start] == 0)--start; if (p[start] == 1 && vis[start] == 1) { return -1; } else { ans += 1; vis[start] = 1; start += m; if (start >= n)break; } } if (start >= n)return ans; return -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...