이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "paint.h"
#include <vector>
#include <iostream>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define pb push_back
#define f first
#define s second
#define ll long long
const int maxn = 1e6 + 200, maxm = 1e3 + 200, inf = 1e9;
int n, m, k;
int is[maxn], dp[maxn];
vector<int> g[maxn];
int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B) {
n = N, m = M, k = K;
for (int i = 0; i < m; ++i){
for (auto it : B[i]){
g[it].pb(i);
}
}
for (int i = m - 1; i < n; ++i){
for (auto it : g[C[i]]){
int x = it;
int ok = 1;
int z = 0;
/* if (i == n - 1){
cout << x << '\n';
}*/
while (z < m){
int ok2 = 0;
for (auto it2 : B[x]){
if (C[i - z] == it2){
ok2 = 1;
break;
}
}
if (ok2 == 0){
ok = 0;
break;
}
x = (x - 1 + m) % m;
z += 1;
}
if (ok == 1){
is[i] = 1;
break;
}
}
}
for (int i = 0; i < n; ++i){
dp[i] = inf;
// cout << is[i] << " ";
}
// cout << '\n';
if (is[m - 1] > 0){
dp[m - 1] = 1;
}
for (int i = m - 1; i < n; ++i){
for (int j = i + 1; j < n && j - i <= m; ++j){
if (is[j]){
dp[j] = min(dp[j], dp[i] + 1);
}
}
}
if (dp[n - 1] == inf){
dp[n - 1] = -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... |