結果

問題 No.2542 Yokan for Two
ユーザー naut3naut3
提出日時 2023-11-24 21:55:31
言語 Rust
(1.77.0)
結果
MLE  
実行時間 -
コード長 2,188 bytes
コンパイル時間 2,027 ms
コンパイル使用メモリ 186,852 KB
実行使用メモリ 812,288 KB
最終ジャッジ日時 2023-11-24 21:55:42
合計ジャッジ時間 6,224 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
23,776 KB
testcase_01 AC 40 ms
29,280 KB
testcase_02 AC 23 ms
18,272 KB
testcase_03 AC 513 ms
351,824 KB
testcase_04 MLE -
testcase_05 MLE -
testcase_06 AC 50 ms
34,884 KB
testcase_07 MLE -
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 #

#![allow(non_snake_case, unused_imports, unused_must_use)]
use std::io::{self, prelude::*};
use std::str;

fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = Scanner::new(stdin.lock());
    let mut out = io::BufWriter::new(stdout.lock());

    macro_rules! input {
        ($T: ty) => {
            scan.token::<$T>()
        };
        ($T: ty, $N: expr) => {
            (0..$N).map(|_| scan.token::<$T>()).collect::<Vec<_>>()
        };
    }

    let L = input!(usize);
    let N = input!(usize);
    let mut X = input!(usize, N);
    X.insert(0, 0);
    X.push(L);

    const MARGIN: usize = 100_010;

    let mut dp = vec![vec![vec![false; 2]; MARGIN + L + 1]; N + 2];
    dp[1][MARGIN + X[1] - X[0]][0] = true;

    for i in 0..=N {
        for j in 0..MARGIN + L + 1 {
            let d = X[i + 1] - X[i];

            if dp[i][j][0] {
                dp[i + 1][j + d][0] = true;
                dp[i + 1][j - d][1] = true;
            }

            if dp[i][j][1] {
                dp[i + 1][j + d][0] = true;
                dp[i + 1][j - d][1] = true;
            }
        }
    }

    let mut ans = 1 << 30;

    for j in 0..MARGIN + L + 1 {
        if dp[N + 1][j][1] {
            ans = std::cmp::min(ans, (j as isize - MARGIN as isize).abs());
        }
    }

    writeln!(out, "{}", ans);
}

struct Scanner<R> {
    reader: R,
    buf_str: Vec<u8>,
    buf_iter: str::SplitWhitespace<'static>,
}
impl<R: BufRead> Scanner<R> {
    fn new(reader: R) -> Self {
        Self {
            reader,
            buf_str: vec![],
            buf_iter: "".split_whitespace(),
        }
    }
    fn token<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse");
            }
            self.buf_str.clear();
            self.reader
                .read_until(b'\n', &mut self.buf_str)
                .expect("Failed read");
            self.buf_iter = unsafe {
                let slice = str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_whitespace())
            }
        }
    }
}
0