답안 #949341

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
949341 2024-03-19T06:36:52 Z vjudge1 벽 칠하기 (APIO20_paint) C++17
0 / 100
1 ms 348 KB
#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
#define size(x) (int)x.size()
#define all(x) x.begin(), x.end()

template<class S, class T> bool chmin(S& a, const T& b) {
  return a > b ? (a = b) == b : false;
}
template<class S, class T> bool chmax(S& a, const T& b) {
  return a < b ? (a = b) == b : false;
}
const int inf = 1e9;

int minimumInstructions(int n, int m, int k, 
  vector<int> c, vector<int> a, vector<vector<int>> b) {
  vector<int> dp(n, inf);
  vector<unordered_map<int, bool>> mp(m);
  for (int i = 0; i < m; ++i) {
    for (auto x : b[i]) {
      mp[i][x] = true;
    }
  }
  for (int i = 0; i + m - 1 < n; ++i) {
    int r = -1;
    for (int k = 0; k < m; ++k) {
      int idx = i - 1;
      bool flag = true;
      for (int j = k; j < m; ++j) {
        if (!mp[j][c[idx + 1]]) {
          flag = false;
          break;
        }
        idx++;
        chmin(idx, n - 1);
      }
      if (flag) {
        for (int j = 0; j < k; ++j) {
          if (!mp[j][c[idx + 1]]) break;
          idx++;
          chmin(idx, n - 1);
        }
      }
      chmax(r, idx);
    }
    if (r == -1) break;
    for (int j = i; j <= r; ++j) {
      if (i) chmin(dp[j], dp[i - 1] + 1);
      else chmin(dp[j], 1);
    }
  }
  return dp[n - 1] == inf ? -1 : dp[n - 1];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Halted 0 ms 0 KB -