結果

問題 No.2542 Yokan for Two
ユーザー titiatitia
提出日時 2023-11-24 22:25:56
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 1,270 bytes
コンパイル時間 1,735 ms
コンパイル使用メモリ 198,376 KB
実行使用メモリ 62,932 KB
最終ジャッジ日時 2023-11-24 22:26:03
合計ジャッジ時間 6,333 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,480 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1,184 ms
59,536 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::HashSet;
use std::cmp::min;

fn main() {
    let mut input_line = String::new();
    std::io::stdin().read_line(&mut input_line).unwrap();
    let mut iter = input_line.split_whitespace();
    let l: i64 = iter.next().unwrap().parse().unwrap();
    let n: i64 = iter.next().unwrap().parse().unwrap();

    input_line.clear();
    std::io::stdin().read_line(&mut input_line).unwrap();
    let x: Vec<i64> = vec![0]
        .into_iter()
        .chain(input_line.split_whitespace().map(|s| s.parse().unwrap()))
        .chain(vec![l].into_iter())
        .collect();

    let mut dp = HashSet::new();
    dp.insert((0, 0, 0));

    for i in 1..=n+1 {
        let mut ndp = HashSet::new();
        for &(ind, d, com) in dp.iter() {
            if com == 0 {
                ndp.insert((i, d + x[i as usize] - x[ind as usize], 1));
            } else {
                ndp.insert((i, d - (x[i as usize] - x[ind as usize]), 0));
            }
        }

        if i != n + 1 {
            dp = ndp.union(&dp).cloned().collect();
        } else {
            dp = ndp;
        }
    }

    let mut ans = i64::MAX;
    for &(_, d, com) in dp.iter() {
        if com == 0 {
            ans = min(ans, d.abs());
        }
    }

    println!("{}", ans);
}
0