結果

問題 No.1965 Heavier
ユーザー phsplsphspls
提出日時 2022-09-13 11:01:16
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,190 bytes
コンパイル時間 7,660 ms
コンパイル使用メモリ 141,536 KB
実行使用メモリ 9,136 KB
最終ジャッジ日時 2023-08-20 12:26:26
合計ジャッジ時間 8,456 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 0 ms
4,384 KB
testcase_06 AC 22 ms
8,720 KB
testcase_07 AC 22 ms
8,788 KB
testcase_08 AC 21 ms
8,476 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 21 ms
8,564 KB
testcase_26 AC 19 ms
8,320 KB
testcase_27 AC 23 ms
9,136 KB
testcase_28 AC 23 ms
9,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();
    let mut a = String::new();
    std::io::stdin().read_line(&mut a).ok();
    let a: Vec<usize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let mut b = String::new();
    std::io::stdin().read_line(&mut b).ok();
    let b: Vec<usize> = b.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let mut result = 0usize;
    let mut ok = vec![false; n-1];
    for i in 0..n-1 {
        let minval = b[i].min(b[i+1]);
        let maxval = b[i].max(b[i+1]);
        ok[i] = a[i] + maxval < a[i+1] + minval;
        if ok[i] {
            result += 1;
        }
    }
    let mut idx = 0usize;
    for i in 0..n-1 {
        if !ok[i] {
            continue;
        }
        idx = idx.max(i+2);
        while idx < n {
            let minval = b[i].min(b[idx]);
            let maxval = b[i].max(b[idx]);
            if a[i] + maxval < a[idx] + minval {
                idx += 1;
            } else {
                break;
            }
        }
        result += idx - i - 2;
    }
    println!("{}", result);
}
0