結果
| 問題 | No.2542 Yokan for Two | 
| コンテスト | |
| ユーザー |  titia | 
| 提出日時 | 2023-11-24 22:25:56 | 
| 言語 | Rust (1.83.0 + proconio) | 
| 結果 | 
                                TLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,270 bytes | 
| コンパイル時間 | 14,879 ms | 
| コンパイル使用メモリ | 377,976 KB | 
| 実行使用メモリ | 61,632 KB | 
| 最終ジャッジ日時 | 2024-09-26 09:32:32 | 
| 合計ジャッジ時間 | 17,946 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | TLE * 1 -- * 39 | 
ソースコード
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);
}
            
            
            
        