답안 #902420

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
902420 2024-01-10T11:49:26 Z nguyentunglam 벽 칠하기 (APIO20_paint) C++17
0 / 100
2 ms 6752 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;

const int N = 2e5 + 10;

bool good[N];

int n, m, k;

int f[N], g[N], bit[N], dp[N];

vector<int> color[N];

int minimumInstructions(int N, int M, int K, std::vector<int> c, std::vector<int> a, std::vector<std::vector<int>> b) {
  n = N; m = M; k = K;
  for(int i = 0; i < m; i++) {
    for(int &j : b[i]) {
      color[j].push_back(i);
//      cout << i << " " << j << endl;
    }
  }
  for(int i = n - 1; i >= 0; i--) {
    for(int &j : color[c[i]]) {
      f[j] = g[(j + 1) % m] + 1;
      if (f[j] >= m) good[i] = 1;
    }
    for(int &j : color[c[i]]) {
      g[j] = f[j];
      f[j] = 0;
    }
  }

  for(int i = 0; i < n; i++) dp[i] = 1e9;

  if (!good[n - m]) return -1;

  dp[n - m] = 1;

  for(int i = n - m - 1; i >= 0; i--) {
    if (good[i]) for(int j = i + 1; j <= i + m; j++) dp[i] = min(dp[i], dp[j] + 1);
//    cout << dp[i] << " " << i << endl;
  }

  return dp[0];
}

#ifdef ngu
int main() {

  freopen ("task.inp", "r", stdin);
  freopen ("task.out", "w", stdout);

  cin >> n >> m >> k;

  vector<int> c(n), a(m);

  vector<vector<int> > b;

  for(int i = 0; i < n; i++) cin >> c[i];

//  for(int i = 0; i < n; i++) cout << c[i] << " "; cout << endl;

  for(int i = 0; i < m; i++) {
    cin >> a[i];
    vector<int> tmp(a[i]);
    for(int j = 0; j < a[i]; j++) cin >> tmp[j];
    b.push_back(tmp);
  }
  cout << minimumInstructions(n, m, k, c, a, b);
}
#endif // ngu

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 2 ms 6744 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6752 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 1 ms 6752 KB Output is correct
9 Incorrect 2 ms 6744 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 2 ms 6744 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6752 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 1 ms 6752 KB Output is correct
9 Incorrect 2 ms 6744 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 2 ms 6744 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6752 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 1 ms 6752 KB Output is correct
9 Incorrect 2 ms 6744 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 2 ms 6744 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6752 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 1 ms 6752 KB Output is correct
9 Incorrect 2 ms 6744 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 2 ms 6744 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6752 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 1 ms 6752 KB Output is correct
9 Incorrect 2 ms 6744 KB Output isn't correct
10 Halted 0 ms 0 KB -