제출 #983193

#제출 시각아이디문제언어결과실행 시간메모리
983193vjudge2벽 칠하기 (APIO20_paint)C++17
100 / 100
1222 ms15008 KiB
#include "paint.h" #include <bits/stdc++.h> using namespace std; const int inf = 1e9; int md(int x, int y) { return (x % y + y) % y; } int minimumInstructions (int n, int m, int k, std::vector<int> a, std::vector<int> SZ, std::vector<std::vector<int>> b) { vector<vector<int>> f(k); for (int i = 0; i < m; i++) for (int j : b[i]) { f[j].push_back(i); // cout << j << ' ' << i << '\n'; } deque<pair<int, int>> dq; vector<int> cnt(m, 0); vector<int> dp(n, 0); dq.push_back({0, -1}); for (int i = 0; i < n; i++) { vector<int> goat; if (i >= m) for (int j : f[a[i - m]]) --cnt[md(j - i + m, m)]; for (int j : f[a[i]]) { cnt[md(j - i, m)]++; if (cnt[md(j - i, m)] == m) goat.push_back(md(j - i, m)); } if (!goat.empty()) { // cout << i << '\n'; // for (int j : goat) cout << j << ' '; // cout << '\n'; while (!dq.empty() && dq.front().second < i - m) dq.pop_front(); if (i >= m - 1 && !dq.empty()) dp[i] = min(inf, dq.front().first + 1); else dp[i] = inf; // older time ones are better while (!dq.empty() && dq.back().first >= dp[i]) dq.pop_back(); dq.push_back({dp[i], i}); } else dp[i] = inf; // for (int j = 0; j < m; j++) cout << cnt[j] << ' '; // cout << '\n'; // cout << "dp " << i << " = " << dp[i] << '\n'; } if (dp[n - 1] >= inf) return -1; return dp[n - 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...