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 <bits/stdc++.h>
#define ll long long
#define ld long double
#define vt vector
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
#define print(x) cout << x << endl
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")
//#define endl '\n'
//#define int long long
using namespace std;
int minimumInstructions(int N, int M, int K, vt<int> C, vt<int> A, vt<vt<int>> B)
{
map<int, int> MP;
for(int i = 0; i < M; i++)
{
for(int x : B[i])
{
MP[x] = i + 1;
}
}
int i, j, ans;
i = j = ans = 0;
while(i <= N - M)
{
if (MP[C[i]] == 0) return -1;
j = i + 1;
while(j < N)
{
//if (MP[C[j]] == 0) return -1;
if (MP[C[j]] - 1 != MP[C[j - 1]] % M) break;
j++;
}
j--;
if (j - i + 1 < M) return -1;
ans += (j - i + M) / M;
i = j + 1;
}
if (i != N) return -1;
return ans;
}
/**
main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int ans = minimumInstructions(6, 4, 4, {2, 1, 0, 3, 2, 1}, {3}, {{2}, {1}, {0}, {3}});
print(ans);
}
/**/
Compilation message (stderr)
paint.cpp:59:1: warning: "/*" within comment [-Wcomment]
59 | /**/
|
# | 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... |