이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << " "
#define nl cout << "\n"
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B){
vector<int> pos[K + 1];
rep(i, 0, N) pos[C[i]].pb(i);
vector<int> workers[N + 1];
rep(i, 0, M){
for(int col : B[i]){
for(int p : pos[col]){
workers[p].pb(i);
}
}
}
vector<bool> v(N + 1, false);
rep(y, 0, N - M + 1){
for(int x : workers[y]){
bool ok = true;
rep(l, 0, M){
int i = (x + l) % M, j = y + l;
auto it = lower_bound(all(B[i]), C[j]);
if(it != B[i].end() && *it == C[j]) continue;
ok = false; break;
}
if(ok){
v[y] = true; break;
}
}
}
vector<int> dp(N, INT_MAX);
if(v[0]) dp[0] = 0;
rep(i, 0, N){
if(v[i] && dp[i] != INT_MAX){
rep(j, i + 1, min(N, i + M + 1)){
dp[j] = min(dp[j], dp[i] + 1);
}
}
}
if(dp[N - 1] == INT_MAX) return -1;
return dp[N - 1];
}
# | 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... |