This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
#define fi first
#define se second
const int INF = 1e9+1;
const int P = 1000000007;
const ll LLINF = (ll)1e18+1;
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) { os << p.fi << " " << p.se; return os; }
template <typename T>
ostream& operator<<(ostream& os, const deque<T>& v) { for(auto i : v) os << i << " "; os << "\n"; return os; }
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) { for(auto i : v) os << i << " "; os << "\n"; return os; }
int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B) {
vector<vector<int>> work(K);
for(int i = 0; i < M; i++)
for(auto j : B[i])
work[j].push_back(i);
//cout << " " << work;
vector<vector<int>> can(M);
for(int i = 0; i < N; i++)
for(auto j : work[C[i]])
can[(((j-i)%M)+M)%M].push_back(i);
//cout << " " << can;
vector<bool> paint(N, false);
for(int i = 0; i < M; i++)
for(int j = M-1; j < can[i].size(); j++)
if(can[i][j] - can[i][j-M+1] == M-1)
paint[can[i][j]] = true;
//cout << paint;
vector<int> dp(N, INF);
if(paint[M-1]) fill(dp.begin(), dp.begin()+M, 1);
for(int i = M; i < N; i++) {
if(!paint[i]) continue;
dp[i] = min(dp[i], dp[i-M]+1);
for(int j = i-1; j >= 0 && !paint[j]; j--) dp[j] = dp[i];
}
if(dp.back() == INF) return -1;
else return dp.back();
}
Compilation message (stderr)
paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:34:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(int j = M-1; j < can[i].size(); j++)
| ~~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |