結果

問題 No.1767 BLUE to RED
ユーザー koba-e964koba-e964
提出日時 2021-11-26 23:35:06
言語 Rust
(1.77.0)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 1,588 bytes
コンパイル時間 2,738 ms
コンパイル使用メモリ 154,848 KB
実行使用メモリ 5,296 KB
最終ジャッジ日時 2023-09-12 05:37:39
合計ジャッジ時間 5,082 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 62 ms
4,376 KB
testcase_10 AC 82 ms
4,376 KB
testcase_11 AC 67 ms
4,380 KB
testcase_12 AC 63 ms
4,380 KB
testcase_13 AC 89 ms
4,576 KB
testcase_14 AC 109 ms
5,116 KB
testcase_15 AC 109 ms
5,116 KB
testcase_16 AC 111 ms
5,076 KB
testcase_17 AC 109 ms
5,080 KB
testcase_18 AC 110 ms
5,024 KB
testcase_19 AC 109 ms
5,084 KB
testcase_20 AC 109 ms
5,100 KB
testcase_21 AC 109 ms
5,104 KB
testcase_22 AC 110 ms
5,296 KB
testcase_23 AC 110 ms
5,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp::*;
// 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 ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
    input! {
        n: usize, m: usize,
        a: [i64; n],
        b: [i64; m],
    }
    const INF: i64 = 1 << 50;
    let mut pos = 0;
    let mut ans = 0;
    for i in 0..n + 1 {
        let lo = if i == 0 { -INF } else { a[i - 1] };
        let hi = if i == n { INF } else { a[i] };
        let mut dp = vec![lo];
        while pos < m && b[pos] < hi {
            dp.push(b[pos]);
            pos += 1;
        }
        dp.push(hi);
        let mut ma = 0;
        for i in 0..dp.len() - 1 {
            ma = max(ma, dp[i + 1] - dp[i]);
        }
        ans += hi - lo - ma;
    }
    println!("{}", ans);
}
0