Submission #902418

# Submission time Handle Problem Language Result Execution time Memory
902418 2024-01-10T11:47:29 Z nguyentunglam Painting Walls (APIO20_paint) C++17
0 / 100
1 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

# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 6752 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 6752 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 6752 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 6752 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 6752 KB Output isn't correct
2 Halted 0 ms 0 KB -