結果

問題 No.1508 Avoid being hit
ユーザー koba-e964koba-e964
提出日時 2021-12-25 01:27:30
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 3,480 bytes
コンパイル時間 1,770 ms
コンパイル使用メモリ 190,876 KB
実行使用メモリ 9,736 KB
最終ジャッジ日時 2023-10-20 05:07:55
合計ジャッジ時間 34,292 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,173 ms
7,624 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 WA -
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1,002 ms
7,624 KB
testcase_17 AC 595 ms
5,248 KB
testcase_18 AC 431 ms
4,348 KB
testcase_19 AC 876 ms
6,832 KB
testcase_20 AC 1,169 ms
8,680 KB
testcase_21 AC 789 ms
6,304 KB
testcase_22 AC 987 ms
7,624 KB
testcase_23 AC 1,051 ms
7,888 KB
testcase_24 AC 1,670 ms
9,736 KB
testcase_25 AC 1,540 ms
9,208 KB
testcase_26 AC 107 ms
4,348 KB
testcase_27 AC 771 ms
5,512 KB
testcase_28 AC 783 ms
5,512 KB
testcase_29 AC 1,571 ms
9,208 KB
testcase_30 AC 838 ms
5,776 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 403 ms
4,348 KB
testcase_34 AC 1,341 ms
7,624 KB
testcase_35 AC 132 ms
4,348 KB
testcase_36 AC 748 ms
5,248 KB
testcase_37 AC 328 ms
4,348 KB
testcase_38 AC 1,080 ms
6,568 KB
testcase_39 AC 690 ms
4,984 KB
testcase_40 AC 1,394 ms
7,888 KB
testcase_41 AC 799 ms
5,248 KB
testcase_42 AC 1,409 ms
8,152 KB
testcase_43 AC 1,671 ms
9,208 KB
testcase_44 AC 1 ms
4,348 KB
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() {
    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 > 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] = nv.clone();
        eprintln!("{} => {:?}", i, nv);
    }
    if v == [(1, n + 1)] {
        puts!("NO\n");
        return;
    }
    let mut vac = ch[0][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