Submission #546265

#TimeUsernameProblemLanguageResultExecution timeMemory
546265cig32Painting Walls (APIO20_paint)C++17
28 / 100
1590 ms524288 KiB
#include "paint.h"
#include <iostream>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <map>
using namespace std;
int minimumInstructions(int N, int M, int K, std::vector<int> C,std::vector<int> A, std::vector<std::vector<int>> B) {
  int dp[N];
  for(int i=0; i<N; i++) dp[i] = 1e9;
  vector<int> contains[K]; // size of contains[i] = f(i)
  for(int i=0; i<M; i++) {
    for(int j=0; j<B[i].size(); j++) {
      contains[B[i][j]].push_back(i);
    }
  }
  unordered_map<int, int> val[N]; // val[i][j] := maximum chain if i choose contractor j at position i
  int mxchain[N];
  for(int i=0; i<N; i++) {
    mxchain[i] = -1e9;
  }
  for(int i=N-1; i>=0; i--) {
    for(int j: contains[C[i]]) {
      val[i][j] = max(val[i][j], (i+1 == N ? 0 : val[i+1][(j+1) % M]) + 1);
      mxchain[i] = max(mxchain[i], val[i][j]);
    }
  }
  for(int i=M-1; i<N; i++) {
    if(mxchain[i-M+1] >= M) {
      for(int j=i-M; j<i; j++) {
        dp[i] = min(dp[i], (j<0 ? 0 : dp[j]) + 1);
      }
    }
  }
  return (dp[N-1] > 1e8 ? -1 : dp[N-1]);
}

Compilation message (stderr)

paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:13:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for(int j=0; j<B[i].size(); j++) {
      |                  ~^~~~~~~~~~~~
#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...