結果

問題 No.2542 Yokan for Two
ユーザー tnakao0123tnakao0123
提出日時 2023-11-25 21:35:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 923 bytes
コンパイル時間 603 ms
コンパイル使用メモリ 42,304 KB
実行使用メモリ 21,720 KB
最終ジャッジ日時 2023-11-25 21:35:48
合計ジャッジ時間 1,994 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 5 ms
9,304 KB
testcase_04 AC 7 ms
19,540 KB
testcase_05 AC 8 ms
13,400 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 14 ms
21,592 KB
testcase_08 AC 6 ms
9,320 KB
testcase_09 AC 13 ms
21,588 KB
testcase_10 AC 4 ms
11,348 KB
testcase_11 AC 5 ms
15,448 KB
testcase_12 AC 7 ms
11,360 KB
testcase_13 AC 4 ms
11,352 KB
testcase_14 AC 9 ms
21,712 KB
testcase_15 AC 11 ms
21,712 KB
testcase_16 AC 9 ms
21,716 KB
testcase_17 AC 10 ms
21,716 KB
testcase_18 AC 10 ms
21,720 KB
testcase_19 AC 7 ms
21,588 KB
testcase_20 AC 7 ms
21,588 KB
testcase_21 AC 10 ms
21,588 KB
testcase_22 AC 7 ms
21,592 KB
testcase_23 AC 8 ms
21,592 KB
testcase_24 AC 3 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 3 ms
6,676 KB
testcase_27 AC 3 ms
6,676 KB
testcase_28 AC 3 ms
6,676 KB
testcase_29 AC 5 ms
9,304 KB
testcase_30 AC 9 ms
21,588 KB
testcase_31 AC 8 ms
21,588 KB
testcase_32 AC 8 ms
21,588 KB
testcase_33 AC 9 ms
21,588 KB
testcase_34 AC 11 ms
21,588 KB
testcase_35 AC 11 ms
21,588 KB
testcase_36 AC 11 ms
21,588 KB
testcase_37 AC 10 ms
21,588 KB
testcase_38 AC 10 ms
21,584 KB
testcase_39 AC 11 ms
21,584 KB
testcase_40 AC 10 ms
21,588 KB
testcase_41 AC 10 ms
21,588 KB
testcase_42 AC 10 ms
21,588 KB
testcase_43 AC 11 ms
21,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2542.cc:  No.2542 Yokan for Two - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_L = 100000;
const int MAX_L2 = MAX_L * 2;
const int MAX_N = 100;
const int INF = 1 << 30;

/* typedef */

/* global variables */

int xs[MAX_N];
bool dp[MAX_N][MAX_L2 + 1];

/* subroutines */

/* main */

int main() {
  int l, n;
  scanf("%d%d", &l, &n);
  for (int i = 0; i < n; i++) scanf("%d", xs + i);

  int j0 = l, j1 = l;
  dp[0][j0] = true;
  for (int i = 0; i + 1 < n; i++) {
    int dx = xs[i + 1] - xs[i];
    for (int j = j0; j <= j1; j++)
      if (dp[i][j])
	dp[i + 1][j + dx] = dp[i + 1][j - dx] = true;
    j0 -= dx, j1 += dx;
  }

  int mind = INF, d0 = xs[0] - (l - xs[n - 1]);
  for (int j = j0; j <= j1; j++)
    if (dp[n - 1][j])
      mind = min(mind, abs(j - l + xs[0] - (l - xs[n - 1])));

  printf("%d\n", mind);
  return 0;
}
0