結果

問題 No.1508 Avoid being hit
ユーザー koba-e964koba-e964
提出日時 2021-12-25 01:22:41
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 3,719 bytes
コンパイル時間 4,165 ms
コンパイル使用メモリ 194,088 KB
実行使用メモリ 7,628 KB
最終ジャッジ日時 2023-10-20 05:04:04
合計ジャッジ時間 28,008 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
4,348 KB
testcase_03 RE -
testcase_04 WA -
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1 ms
4,348 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1,000 ms
6,836 KB
testcase_17 AC 578 ms
4,460 KB
testcase_18 AC 423 ms
4,348 KB
testcase_19 AC 864 ms
6,044 KB
testcase_20 AC 1,168 ms
7,628 KB
testcase_21 AC 772 ms
5,516 KB
testcase_22 AC 988 ms
6,572 KB
testcase_23 AC 1,042 ms
7,100 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
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[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);
    }
}
0