結果

問題 No.808 Kaiten Sushi?
ユーザー koba-e964koba-e964
提出日時 2019-03-23 02:04:38
言語 Rust
(1.72.1)
結果
WA  
実行時間 -
コード長 2,791 bytes
コンパイル時間 2,002 ms
コンパイル使用メモリ 195,060 KB
実行使用メモリ 7,140 KB
最終ジャッジ日時 2023-10-19 15:44:53
合計ジャッジ時間 5,538 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 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 WA -
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 18 ms
4,348 KB
testcase_24 AC 15 ms
4,348 KB
testcase_25 AC 17 ms
4,348 KB
testcase_26 AC 17 ms
4,348 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 57 ms
7,040 KB
testcase_33 AC 28 ms
4,348 KB
testcase_34 AC 29 ms
4,652 KB
testcase_35 AC 36 ms
5,336 KB
testcase_36 AC 29 ms
4,348 KB
testcase_37 AC 1 ms
4,348 KB
testcase_38 AC 1 ms
4,348 KB
testcase_39 AC 51 ms
6,716 KB
testcase_40 AC 11 ms
4,348 KB
testcase_41 AC 14 ms
4,348 KB
testcase_42 AC 43 ms
5,724 KB
testcase_43 AC 19 ms
4,348 KB
testcase_44 AC 32 ms
4,652 KB
testcase_45 AC 19 ms
4,348 KB
testcase_46 AC 12 ms
4,348 KB
testcase_47 AC 57 ms
7,140 KB
testcase_48 AC 58 ms
7,140 KB
testcase_49 AC 57 ms
7,140 KB
testcase_50 AC 57 ms
7,140 KB
testcase_51 AC 58 ms
7,140 KB
testcase_52 AC 43 ms
5,344 KB
testcase_53 AC 58 ms
7,040 KB
testcase_54 AC 1 ms
4,348 KB
testcase_55 AC 1 ms
4,348 KB
testcase_56 AC 1 ms
4,348 KB
testcase_57 AC 17 ms
4,348 KB
testcase_58 AC 31 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);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        l: i64,
        x: [i64; n],
        y: [i64; n],
    }
    let mut st = vec![];
    for i in 0..n {
        st.push((x[i], 1));
        st.push((y[i], -1));
    }
    st.sort();
    let mut acc = vec![0; 2 * n + 1];
    for i in 0..2 * n {
        acc[i + 1] = acc[i] + st[i].1;
    }
    let mut mi = (0, 0);
    for i in 0..2 * n {
        mi = min(mi, (acc[i], i));
    }
    let mut ma = (0, 0);
    for i in 0..2 * n {
        let diff = if i < mi.1 { if acc[i] > 0 { -1 } else { 0 } } else { 0 };
        ma = max(ma, (acc[i] - mi.0 + diff, (i + 2 * n - mi.1) % (2 * n)));
    }
    eprintln!("mi = {:?}, ma = {:?}", mi, ma);
    let mut tot = l * (ma.0 - 1) + st[(ma.1 + mi.1) % (2 * n)].0;
    if ma.1 + mi.1 >= 2 * n {
        tot += l;
    }
    puts!("{}\n", tot);
}

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