結果

問題 No.2542 Yokan for Two
ユーザー Maxdorian
提出日時 2023-11-24 22:01:54
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,067 bytes
コンパイル時間 5,554 ms
コンパイル使用メモリ 307,996 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-26 09:19:41
合計ジャッジ時間 7,126 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26 WA * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
template <class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const int INF = INT_MAX / 2;
const ll LINF = 1LL << 60;
const vector<int> dx = {-1, 0, 1, 0}, dy = {0, 1, 0, -1};
using mint = modint998244353;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int l, n;
  cin >> l >> n;
  vector<int> x;
  x.push_back(0);
  for (int i = 0; i < n; i++) {
    int val;
    cin >> val;
    x.push_back(val);
  }
  x.push_back(l);
  vector<int> dp(n + 2, INF);
  dp[0] = 0;
  for (int i = 2; i <= n + 1; i++) {
    for (int j = 0; j <= i - 2; j++) {
      for (int k = j + 1; k <= i - 1; k++) {
        if (abs(dp[i]) > abs(dp[j] + (x[k] - x[j]) - (x[i] - x[k]))) {
          dp[i] = dp[j] + (x[k] - x[j]) - (x[i] - x[k]);
        }
      }
    }
  }
  cout << abs(dp[n + 1]) << '\n';
  return 0;
}
0