Submission #902424

#TimeUsernameProblemLanguageResultExecution timeMemory
902424nguyentunglamPainting Walls (APIO20_paint)C++17
0 / 100
2 ms6748 KiB
#include<bits/stdc++.h> #define fi first #define se second #define endl "\n" #define ii pair<int, int> using namespace std; const int N = 2e5 + 10; bool good[N]; int n, m, k; int f[N], g[N], bit[N], dp[N]; vector<int> color[N]; int minimumInstructions(int N, int M, int K, std::vector<int> c, std::vector<int> a, std::vector<std::vector<int>> b) { n = N; m = M; k = K; for(int i = 0; i < m; i++) { for(int &j : b[i]) { color[j].push_back(i); // cout << i << " " << j << endl; } } for(int i = n - 1; i >= 0; i--) { for(int &j : color[c[i]]) { f[j] = g[(j + 1) % m] + 1; if (f[j] >= m) good[i] = 1; } if (i + 1 < n) for(int &j : color[c[i + 1]]) g[j] = 0; for(int &j : color[c[i]]) { g[j] = f[j]; f[j] = 0; } } for(int i = 0; i < n; i++) dp[i] = 1e9; if (!good[n - m]) return -1; dp[n - m] = 1; for(int i = n - m - 1; i >= 0; i--) { if (good[i]) for(int j = i + 1; j <= i + m; j++) dp[i] = min(dp[i], dp[j] + 1); // cout << dp[i] << " " << i << endl; } return dp[0]; } #ifdef ngu int main() { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); int n, m, k; cin >> n >> m >> k; vector<int> c(n), a(m); vector<vector<int> > b; for(int i = 0; i < n; i++) cin >> c[i]; // for(int i = 0; i < n; i++) cout << c[i] << " "; cout << endl; for(int i = 0; i < m; i++) { cin >> a[i]; vector<int> tmp(a[i]); for(int j = 0; j < a[i]; j++) cin >> tmp[j]; b.push_back(tmp); } cout << minimumInstructions(n, m, k, c, a, b); } #endif // ngu
#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...