Submission #981617

#TimeUsernameProblemLanguageResultExecution timeMemory
981617yoav_sPainting Walls (APIO20_paint)C++17
51 / 100
341 ms524288 KiB
#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" typedef bitset<50000> bs; 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]; } vb poss(N - M + 1); for (ll i = 0; i <= N - M; i++) poss[i] = query(i, i + M - 1, validStartIndices); 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 (poss[lastDone]) 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:3: warning: ignoring '#pragma optimization_level ' [-Wunknown-pragmas]
    3 | #pragma optimization_level 3
      | 
paint.cpp:8: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    8 | #pragma GCC optimization ("unroll-loops")
      | 
paint.cpp:140:1: warning: "/*" within comment [-Wcomment]
  140 | /**/
      |  
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<50000> >&)':
paint.cpp:55:10: warning: unused variable 'first' [-Wunused-variable]
   55 |     bool first = false;
      |          ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...