結果
問題 | No.2542 Yokan for Two |
ユーザー | naut3 |
提出日時 | 2023-11-24 22:03:00 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 1,158 ms / 2,000 ms |
コード長 | 2,233 bytes |
コンパイル時間 | 14,087 ms |
コンパイル使用メモリ | 378,728 KB |
実行使用メモリ | 23,852 KB |
最終ジャッジ日時 | 2024-09-26 09:21:41 |
合計ジャッジ時間 | 45,265 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 25 ms
12,824 KB |
testcase_01 | AC | 32 ms
12,820 KB |
testcase_02 | AC | 16 ms
12,800 KB |
testcase_03 | AC | 367 ms
23,720 KB |
testcase_04 | AC | 556 ms
15,372 KB |
testcase_05 | AC | 623 ms
22,144 KB |
testcase_06 | AC | 37 ms
18,432 KB |
testcase_07 | AC | 997 ms
22,920 KB |
testcase_08 | AC | 305 ms
21,644 KB |
testcase_09 | AC | 999 ms
22,852 KB |
testcase_10 | AC | 308 ms
15,452 KB |
testcase_11 | AC | 409 ms
15,252 KB |
testcase_12 | AC | 485 ms
21,888 KB |
testcase_13 | AC | 299 ms
14,976 KB |
testcase_14 | AC | 1,114 ms
22,988 KB |
testcase_15 | AC | 1,145 ms
23,500 KB |
testcase_16 | AC | 1,126 ms
23,084 KB |
testcase_17 | AC | 1,054 ms
22,972 KB |
testcase_18 | AC | 1,139 ms
23,680 KB |
testcase_19 | AC | 820 ms
18,836 KB |
testcase_20 | AC | 805 ms
18,212 KB |
testcase_21 | AC | 804 ms
18,220 KB |
testcase_22 | AC | 843 ms
18,304 KB |
testcase_23 | AC | 889 ms
18,432 KB |
testcase_24 | AC | 98 ms
23,840 KB |
testcase_25 | AC | 141 ms
23,720 KB |
testcase_26 | AC | 139 ms
23,716 KB |
testcase_27 | AC | 155 ms
23,592 KB |
testcase_28 | AC | 161 ms
23,848 KB |
testcase_29 | AC | 305 ms
23,848 KB |
testcase_30 | AC | 1,119 ms
23,720 KB |
testcase_31 | AC | 1,147 ms
23,720 KB |
testcase_32 | AC | 1,144 ms
23,724 KB |
testcase_33 | AC | 1,133 ms
23,720 KB |
testcase_34 | AC | 1,129 ms
23,720 KB |
testcase_35 | AC | 1,115 ms
23,852 KB |
testcase_36 | AC | 1,137 ms
23,720 KB |
testcase_37 | AC | 1,126 ms
23,720 KB |
testcase_38 | AC | 1,145 ms
23,720 KB |
testcase_39 | AC | 1,129 ms
23,848 KB |
testcase_40 | AC | 1,124 ms
23,724 KB |
testcase_41 | AC | 1,146 ms
23,764 KB |
testcase_42 | AC | 1,158 ms
23,720 KB |
testcase_43 | AC | 1,131 ms
23,592 KB |
ソースコード
#![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![false; 2]; MARGIN + L + 1]; dp[MARGIN + X[1] - X[0]][0] = true; for i in 1..=N { let mut nxt_dp = vec![vec![false; 2]; MARGIN + L + 1]; for j in 0..MARGIN + L + 1 { let d = X[i + 1] - X[i]; if dp[j][0] { nxt_dp[j + d][0] = true; nxt_dp[j - d][1] = true; } if dp[j][1] { nxt_dp[j + d][0] = true; nxt_dp[j - d][1] = true; } } dp = nxt_dp; } let mut ans = 1 << 30; for j in 0..MARGIN + L + 1 { if dp[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()) } } } }