結果
問題 | No.1508 Avoid being hit |
ユーザー | koba-e964 |
提出日時 | 2021-12-25 01:22:41 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,719 bytes |
コンパイル時間 | 23,000 ms |
コンパイル使用メモリ | 379,732 KB |
実行使用メモリ | 8,704 KB |
最終ジャッジ日時 | 2024-09-20 00:46:37 |
合計ジャッジ時間 | 38,663 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | RE | - |
testcase_04 | WA | - |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | AC | 1 ms
5,376 KB |
testcase_16 | AC | 937 ms
7,808 KB |
testcase_17 | AC | 556 ms
5,376 KB |
testcase_18 | AC | 392 ms
5,376 KB |
testcase_19 | AC | 788 ms
7,040 KB |
testcase_20 | AC | 1,105 ms
8,704 KB |
testcase_21 | AC | 719 ms
6,528 KB |
testcase_22 | AC | 908 ms
7,680 KB |
testcase_23 | AC | 958 ms
8,192 KB |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | RE | - |
testcase_40 | RE | - |
testcase_41 | RE | - |
testcase_42 | RE | - |
testcase_43 | RE | - |
testcase_44 | WA | - |
testcase_45 | AC | 1 ms
5,376 KB |
ソースコード
#[allow(unused_imports)] use std::cmp::*; #[allow(unused_imports)] use std::collections::*; use std::io::{Write, BufWriter}; // https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 macro_rules! input { ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char) .skip_while(|c|c.is_whitespace()) .take_while(|c|!c.is_whitespace()) .collect() }; input_inner!{next, $($r)*} }; } macro_rules! input_inner { ($next:expr) => {}; ($next:expr,) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; } macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ($(read_value!($next, $t)),*) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, usize1) => (read_value!($next, usize) - 1); ($next:expr, [ $t:tt ]) => {{ let len = read_value!($next, usize); read_value!($next, [$t; len]) }}; ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); } trait Change { fn chmax(&mut self, x: Self); fn chmin(&mut self, x: Self); } impl<T: PartialOrd> Change for T { fn chmax(&mut self, x: T) { if *self < x { *self = x; } } fn chmin(&mut self, x: T) { if *self > x { *self = x; } } } fn main() { // In order to avoid potential stack overflow, spawn a new thread. let stack_size = 104_857_600; // 100 MB let thd = std::thread::Builder::new().stack_size(stack_size); thd.spawn(|| solve()).unwrap().join().unwrap(); } fn solve() { let out = std::io::stdout(); let mut out = BufWriter::new(out.lock()); macro_rules! puts {($($format:tt)*) => (let _ = write!(out,$($format)*););} input! { n: usize, q: usize, a: [usize; q], b: [usize; q], } let mut v = vec![]; let mut ch = vec![vec![]; q]; for i in (0..q).rev() { v.push((a[i], a[i] + 1)); v.push((b[i], b[i] + 1)); v.sort(); let mut nv = vec![]; let mut st = 0; let mut last = 0; for &(l, r) in &v { if last < l { if last > 0 { nv.push((st, last)); } st = l; last = r; } else { last = r; } } nv.push((st, last)); v.clear(); for &(l, r) in &nv { if l == 1 && r == n + 1 { v.push((1, n + 1)); } else if l == 1 { if r > 1 { v.push((1, r - 1)); } } else if r == n + 1 { if l < n { v.push((l + 1, n + 1)); } } else { if l + 1 < r - 1 { v.push((l + 1, r - 1)); } } } ch[i] = v.clone(); eprintln!("{} => {:?}", i, v); } if v == [(1, n + 1)] { puts!("NO\n"); return; } let mut vac = v[0].1; puts!("YES\n{}\n{}\n", vac, vac); for i in 1..q { let mut ok = 0; for j in max(1, vac - 1)..min(n, vac + 1) + 1 { if ch[i].iter().all(|&(l, r)| j < l || r <= j) { ok = j; break; } } vac = ok; puts!("{}\n", vac); } }