답안 #908705

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
908705 2024-01-16T17:21:03 Z vjudge1 Pinball (JOI14_pinball) C++17
0 / 100
1 ms 856 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <cstring>
#warning That's the baby, that's not my baby

typedef long long ll;

struct Device {
  int a, b, c, d;
};

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  int n, m;
  std::cin >> n >> m;

  Device a[n + 1];
  std::vector<int> norm;
  norm.push_back(1);
  norm.push_back(n);

  for (int i = 1; i <= n; i++) {
    std::cin >> a[i].a >> a[i].b >> a[i].c >> a[i].d;
    norm.push_back(a[i].a);
    norm.push_back(a[i].b);
    norm.push_back(a[i].c);
  }

  std::sort(norm.begin(), norm.end());
  norm.erase(std::unique(norm.begin(), norm.end()), norm.end());

  for (int i = 1; i <= n; i++) {
    a[i].a = std::lower_bound(norm.begin(), norm.end(), a[i].a) - norm.begin() + 1;
    a[i].b = std::lower_bound(norm.begin(), norm.end(), a[i].b) - norm.begin() + 1;
    a[i].c = std::lower_bound(norm.begin(), norm.end(), a[i].c) - norm.begin() + 1;
  }

  int sz = (int) norm.size();

  ll dp[m + 5][sz + 1][sz + 1];
  for (int i = 0; i <= m; i++) {
    for (int l = 1; l <= sz; l++) {
      for (int r = l; r <= sz; r++) {
        dp[i][l][r] = 1e18;
      }
    }
  }

  dp[0][1][m] = 0;

  for (int i = 1; i <= m; i++) {
    for (int l = 1; l <= sz; l++) {
      for (int r = l; r <= sz; r++) {
        dp[i][l][r] = std::min(dp[i][l][r], dp[i - 1][l][r]);
        int newL = l, newR = r;
        if (a[i].a <= l && l <= a[i].b) {
          newL = a[i].c;
        }
        if (a[i].a <= r && r <= a[i].b) {
          newR = a[i].c;
        }
        dp[i][newL][newR] = std::min(dp[i][newL][newR], dp[i][l][r] + a[i].d);
      }
    }
  }

  ll answer = 1e18;

  for (int i = 1; i <= sz; i++) {
    answer = std::min(answer, dp[m][i][i]);
  }

  if (answer == 1e18) {
    answer = -1;
  }
  std::cout << answer;

  return 0;
}

Compilation message

pinball.cpp:6:2: warning: #warning That's the baby, that's not my baby [-Wcpp]
    6 | #warning That's the baby, that's not my baby
      |  ^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 856 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 856 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 856 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 856 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -