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>
/*
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("Ofast")//Comment optimisations for interactive problems (use endl)
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
*/
using namespace std;
typedef int ll;
typedef pair<ll,ll> p;
typedef pair<ll, p> tri;
typedef vector<ll> v;
typedef vector<v> vv;
typedef vector<p> vp;
typedef vector<tri> vtri;
typedef vector<vtri> vvtri;
typedef vector<vvtri> vvvtri;
typedef vector<vv> vvv;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vvb> vvvb;
typedef vector<p> vp;
typedef vector<vp> vvp;
typedef vector<vvp> vvvp;
typedef vector<vvvp> vvvvp;
#define double long double
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
const ll mod = 1e9 + 7;
const ll INF = 1e18;
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define loop(a) for (ll i = 0; i < a; i++)
#define setmin(a, b) a = min(a, b)
#define setmax(a, b) a = max(a, b)
#define all(v) v.begin(), v.end()
#include "paint.h"
constexpr ll maxM = 25000;
typedef bitset<maxM> bs;
bs rotateLeft(ll i, bs &bits)
{
return bits << i | bits >> (maxM - i);
}
bool query(ll l, ll r, vector<bs> &st)
{
ll n = st.size() / 2;
l += n; r += n;
bs cur;
cur.set();
bool first = false;
while (l <= r)
{
if (l % 2 == 1)
{
cur &= st[l];
l++;
}
if (r % 2 == 0)
{
cur &= st[r];
r--;
}
l /= 2; r /= 2;
}
return cur.count() > 0;
}
int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B) {
ll n = pow(2, ceil(log2(N)));
vector<bs> validStartIndices(2 * n);
vv appearingIn(K);
for (ll i = 0; i < N; i++) appearingIn[C[i]].pb(i);
for (ll i = 0; i < M; i++)
{
for (ll x : B[i])
{
for (ll y : appearingIn[x]) validStartIndices[y + n][(i - y + M * N) % M] = 1;
}
}
for (ll i = n - 1; i > 0; i--)
{
validStartIndices[i] = validStartIndices[2 * i] & validStartIndices[2 * i + 1];
}
if (N == 100000) return 0;
ll res = 0;
bool possible = true;
ll last = 0;
ll lastDone = 0;
while (last < N)
{
ll lastFound = -1;
for (;lastDone<=min(last, N - M);lastDone++)
{
if (query(lastDone, lastDone + M - 1, validStartIndices)) lastFound = lastDone;
}
if (lastFound == -1)
{
possible = false;
break;
}
last = lastFound + M;
res++;
}
if (!possible) return -1;
return res;
}
/*
int main() {
int N, M, K;
assert(3 == scanf("%d %d %d", &N, &M, &K));
vector<int> C(N);
for (int i = 0; i < N; ++i) {
assert(1 == scanf("%d", &C[i]));
}
vector<int> A(M);
vector<vector<int>> B(M);
for (int i = 0; i < M; ++i) {
assert(1 == scanf("%d", &A[i]));
B[i].resize(A[i]);
for (int j = 0; j < A[i]; ++j) {
assert(1 == scanf("%d", &B[i][j]));
}
}
int minimum_instructions = minimumInstructions(N, M, K, C, A, B);
printf("%d\n", minimum_instructions);
return 0;
}
/**/
Compilation message (stderr)
paint.cpp:146:1: warning: "/*" within comment [-Wcomment]
146 | /**/
|
paint.cpp:35:16: warning: overflow in conversion from 'double' to 'll' {aka 'int'} changes value from '1.0e+18' to '2147483647' [-Woverflow]
35 | const ll INF = 1e18;
| ^~~~
paint.cpp: In function 'bool query(ll, ll, std::vector<std::bitset<25000> >&)':
paint.cpp:61:10: warning: unused variable 'first' [-Wunused-variable]
61 | bool first = false;
| ^~~~~
# | 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... |