제출 #548183

#제출 시각아이디문제언어결과실행 시간메모리
548183Soumya1벽 칠하기 (APIO20_paint)C++17
0 / 100
1 ms304 KiB
#include "paint.h"
#include <bits/stdc++.h>
#include <vector>
// #include <debug_local.h>
using namespace std;
int minimumInstructions(int n, int m, int k, vector<int> c, vector<int> a, vector<vector<int>> b) {
  vector<int> l[k];
  for (int i = 0; i < m; i++) {
    for (int j : b[i]) {
      l[j].push_back(i);
    }
  }
  vector<int> last;
  vector<int> f(n);
  for (int j : l[c[n - 1]]) last.push_back(1);
  f[n - 1] = (*max_element(last.begin(), last.end()) >= m);
  for (int i = n - 2; i >= 0; i--) {
    int ptr = 0;
    vector<int> new_last;
    for (int j = 0; j < l[c[i]].size(); j++) {
      while (ptr < l[c[i + 1]].size() && l[c[i + 1]][ptr] < (1 + l[c[i]][j]) % m) ptr++;
      if (l[c[i]][j] == m - 1 && l[c[i + 1]].size() && l[c[i + 1]][0] == 0) new_last.push_back(last[0] + 1);
      else if (ptr < l[c[i + 1]].size() && l[c[i + 1]][ptr] == (1 + l[c[i]][j]) % m) new_last.push_back(last[ptr] + 1);
      else new_last.push_back(1);
    }
    last = new_last;
    f[i] = (*max_element(last.begin(), last.end()) >= m);
  }
  vector<int> s;
  for (int i = n; i > 0; i--) s.push_back(i);
  queue<int> q;
  q.push(0);
  vector<int> dp(n + 1, 1e9);
  dp[0] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    if (u == n) break;
    if (!f[u]) continue;
    dp[u]++;
    while (!s.empty() && s.back() <= u + m) {
      q.push(s.back());
      dp[s.back()] = dp[u];
      s.pop_back();
    }
  }
  return (dp[n] >= 1e9 ? -1 : dp[n]);
  return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:15:12: warning: unused variable 'j' [-Wunused-variable]
   15 |   for (int j : l[c[n - 1]]) last.push_back(1);
      |            ^
paint.cpp:20:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for (int j = 0; j < l[c[i]].size(); j++) {
      |                     ~~^~~~~~~~~~~~~~~~
paint.cpp:21:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |       while (ptr < l[c[i + 1]].size() && l[c[i + 1]][ptr] < (1 + l[c[i]][j]) % m) ptr++;
      |              ~~~~^~~~~~~~~~~~~~~~~~~~
paint.cpp:23:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |       else if (ptr < l[c[i + 1]].size() && l[c[i + 1]][ptr] == (1 + l[c[i]][j]) % m) new_last.push_back(last[ptr] + 1);
      |                ~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...