제출 #1312081

#제출 시각아이디문제언어결과실행 시간메모리
1312081maya_s벽 칠하기 (APIO20_paint)C++20
28 / 100
1502 ms8976 KiB
#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
const ll inf = 1e9;

bool ok(ll start, int m, int k, vector<int> &c, vector<int> &a, vector<set<int>> &s){
  for(ll shift = 0; shift < m; shift++){
    bool lol = 1;
    for(ll i = start; i < start + m && lol; i++){
      if(s[(i + shift) % m].find(c[i]) == s[(i + shift) % m].end()) lol = 0;
    }
    if(lol) return 1;
  }
  return 0;
}

int minimumInstructions(int n, int m, int k, vector<int> c, vector<int> a, vector<vector<int>> b) {
  vector<ll> dp(n, inf); 
  vector<set<ll>> s(m);
  for(ll i = 0; i < m; i++) for(ll j: b[i]) s[i].insert(j);
  dp[m-1] = (ok(0, m, k, c, a, s) ? 1 : inf);
  for(ll i = m; i < n; i++) {
    if(ok(i-m+1, m, k, c, a, s)){
      for(ll j = i-1; j >= i-m; j--) dp[i] = min(dp[i], dp[j]+1);
    }
  }
  return dp[n-1] != inf ? dp[n-1] : -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...