답안 #717467

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
717467 2023-04-02T00:38:18 Z schiftyfive4 벽 칠하기 (APIO20_paint) C++14
0 / 100
1 ms 212 KB
#include "paint.h"
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.hpp"
#else
#define debug(...) "MJ >> LAMELO"
#endif

int minimumInstructions(
    int N, int M, int K, std::vector<int> C,
    std::vector<int> A, std::vector<std::vector<int>> B) {
  vector<vector<int>> g(K);
  for (int i = 0; i < M; i++) {
    for (int j : B[i]) {
      g[j].push_back(i);
    }
  }
  int cnt_m = 0;
  vector<int> cnt(M);
  for (int i = 0; i < M; i++) {
    for (int j : g[C[i]]) {
      int id = (j - i + M) % M;
      cnt[id]++;
      assert(cnt[id] <= M);
      if (cnt[id] == M) {
        cnt_m++;
      }
    }
  }
  if (!cnt_m) {
    return -1;
  }
  int ans = 1;
  int lst = M - 1;
  int best = M - 1;
  for (int i = 1; i + M - 1 < N; i++) {
    for (int j : g[C[i - 1]]) {
      if (cnt[j] == M) {
        cnt_m--;
      }
      cnt[j]--;
      assert(cnt[j] >= 0);
    }
    for (int j : g[C[i + M - 1]]) {
      cnt[(j + 1) % M]++;
      assert(cnt[(j + 1) % M] <= M);
      if (cnt[(j + 1) % M] == M) {
        cnt_m++;
      }
    }
    if (cnt_m) {
      best = i + M - 1;
    }
    if (i == lst + 1) {
      if (best < i) {
        return -1;
      }
      ans++;
      lst = best;
    }
  }
  if (best < N - 1) {
    return -1;
  }
  assert(best == N - 1);
  if (lst < best) {
    ans++;
  }
  // return ans;
  return (N + M - 1) / M;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 1 ms 212 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 1 ms 212 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 1 ms 212 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 1 ms 212 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 1 ms 212 KB Output isn't correct
7 Halted 0 ms 0 KB -