Submission #872459

# Submission time Handle Problem Language Result Execution time Memory
872459 2023-11-13T06:58:18 Z abczz Painting Walls (APIO20_paint) C++14
0 / 100
2 ms 2796 KB
#include "paint.h"
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <array>
#define ll long long

using namespace std;

bool F[100000], ok;
ll f, z, r, cnt[100000];
int minimumInstructions(
    int N, int M, int K, std::vector<int> C,
    std::vector<int> A, std::vector<std::vector<int>> B) {
  vector <ll> X[100000];
  priority_queue<array<ll, 2>> pq;
  for (int i=0; i<N; ++i) F[i] = 0;
  for (int i=0; i<M; ++i) {
    cnt[i] = 0;
    for (int j=0; j<A[i]; ++j) {
      X[B[i][j]].push_back(i);
    }
  }
  for (int i=0; i<M; ++i) {
    for (auto u : X[C[i]]) {
      z = (u-i+M)%M;
      ++cnt[z];
      pq.push({cnt[z], z});
    }
  }
  ok = 0;
  while (!pq.empty()) {
    auto [w, u] = pq.top();
    if (cnt[u] != w) pq.pop();
    else if (w != M) break;
    else {
      ok = 1;
      break;
    }
  }
  if (ok) F[0] = 1;
  for (int i=M; i<N; ++i) {
    for (auto u : X[C[i]]) {
      z = (u-(i%M)+M)%M;
      ++cnt[z];
      pq.push({cnt[z], z});
    }
    for (auto u : X[C[i-M]]) {
      z = (u-((i-M)%M)+M)%M;
      --cnt[z];
      pq.push({cnt[z], z});
    }
    ok = 0;
    while (!pq.empty()) {
      auto [w, u] = pq.top();
      if (cnt[u] != w) pq.pop();
      else if (w != M) break;
      else {
        ok = 1;
        break;
      }
    }
    if (ok) F[i-M+1] = 1;
  }
  if (!F[0]) return -1;
  int i = 0;
  f = 1, r = M;
  while (true) {
    z = -1;
    for (int j=i; j<=min((ll)N, r); ++j) {
      if (j == N) return f;
      if (F[j]) z = max(z, (ll)j);
    }
    if (z == -1 || z == i) return -1;
    i = r+1;
    r = z+M;
    ++f;
  }
}

Compilation message

paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:34:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   34 |     auto [w, u] = pq.top();
      |          ^
paint.cpp:56:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   56 |       auto [w, u] = pq.top();
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 2 ms 2752 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 2 ms 2652 KB Output is correct
5 Correct 2 ms 2652 KB Output is correct
6 Correct 2 ms 2796 KB Output is correct
7 Incorrect 2 ms 2652 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 2 ms 2752 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 2 ms 2652 KB Output is correct
5 Correct 2 ms 2652 KB Output is correct
6 Correct 2 ms 2796 KB Output is correct
7 Incorrect 2 ms 2652 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 2 ms 2752 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 2 ms 2652 KB Output is correct
5 Correct 2 ms 2652 KB Output is correct
6 Correct 2 ms 2796 KB Output is correct
7 Incorrect 2 ms 2652 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 2 ms 2752 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 2 ms 2652 KB Output is correct
5 Correct 2 ms 2652 KB Output is correct
6 Correct 2 ms 2796 KB Output is correct
7 Incorrect 2 ms 2652 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 2 ms 2752 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 2 ms 2652 KB Output is correct
5 Correct 2 ms 2652 KB Output is correct
6 Correct 2 ms 2796 KB Output is correct
7 Incorrect 2 ms 2652 KB Output isn't correct
8 Halted 0 ms 0 KB -