이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define TASK ""
#define bit(x) (1LL << (x))
#define getbit(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r) {
return l + rd() % (r - l + 1);
}
const int N = 1e5 + 5;
const int oo = 1e9;
const long long ooo = 1e18;
const int mod = 1e9 + 7; // 998244353;
const long double pi = acos(-1);
vector <int> pos[N];
vector <int> ok[N];
vector <int> b[N];
int a[N];
int c[N];
int dp[N];
int n,m,k;
bool col[N];
int solve() {
for (int i = 0; i < m; i++)
for (int j = 0; j < a[i]; j++)
pos[b[i][j]].push_back(i);
for (int i = 0; i < n; i++) {
int v = i % m;
for (int j : pos[c[i]]) {
int val = j - v;
if (val < 0)
val += m;
ok[val].push_back(i);
}
}
for (int i = 0; i < m; i++)
for (int l = 0, r = m - 1; r < (int) ok[i].size(); l++, r++)
if (ok[i][r] - ok[i][l] + 1 == m)
col[ok[i][l]] = true;
int ans = 0;
int cur = 0;
int pre = -1;
while (cur < n) {
ans++;
bool found = false;
for (int i = cur; i > pre; i--) if (col[i]) {
found = true;
pre = cur;
cur = i + m;
break;
}
if (!found)
break;
}
if (cur < n)
ans = -1;
return ans;
}
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 < n; i++)
c[i] = C[i];
for (int i = 0; i < m; i++)
a[i] = A[i];
for (int i = 0; i < m; i++) {
b[i].resize(a[i]);
for (int j = 0; j < a[i]; j++)
b[i][j] = B[i][j];
}
return solve();
}
#include "paint.h"
//#include "grader.cpp"
# | 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... |