結果

問題 No.2860 Heal Slimes
ユーザー QiToYQiToY
提出日時 2024-08-25 15:46:56
言語 Rust
(1.77.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 1,842 bytes
コンパイル時間 13,076 ms
コンパイル使用メモリ 392,528 KB
実行使用メモリ 8,576 KB
最終ジャッジ日時 2024-08-25 15:47:13
合計ジャッジ時間 17,572 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
6,816 KB
testcase_01 AC 52 ms
6,944 KB
testcase_02 AC 52 ms
6,940 KB
testcase_03 AC 52 ms
6,940 KB
testcase_04 AC 53 ms
6,944 KB
testcase_05 AC 60 ms
6,940 KB
testcase_06 AC 60 ms
6,940 KB
testcase_07 AC 61 ms
6,940 KB
testcase_08 AC 60 ms
6,940 KB
testcase_09 AC 61 ms
6,940 KB
testcase_10 AC 14 ms
6,940 KB
testcase_11 AC 13 ms
6,940 KB
testcase_12 AC 13 ms
6,944 KB
testcase_13 AC 13 ms
6,940 KB
testcase_14 AC 13 ms
6,940 KB
testcase_15 AC 19 ms
6,940 KB
testcase_16 AC 18 ms
6,940 KB
testcase_17 AC 19 ms
6,940 KB
testcase_18 AC 19 ms
6,940 KB
testcase_19 AC 19 ms
6,944 KB
testcase_20 AC 15 ms
6,940 KB
testcase_21 AC 15 ms
7,040 KB
testcase_22 AC 10 ms
6,944 KB
testcase_23 AC 19 ms
8,448 KB
testcase_24 AC 17 ms
7,936 KB
testcase_25 AC 12 ms
6,940 KB
testcase_26 AC 10 ms
6,944 KB
testcase_27 AC 20 ms
6,944 KB
testcase_28 AC 21 ms
7,936 KB
testcase_29 AC 14 ms
6,940 KB
testcase_30 AC 17 ms
7,808 KB
testcase_31 AC 21 ms
8,192 KB
testcase_32 AC 19 ms
8,192 KB
testcase_33 AC 21 ms
7,936 KB
testcase_34 AC 20 ms
8,576 KB
testcase_35 AC 22 ms
8,064 KB
testcase_36 AC 20 ms
7,808 KB
testcase_37 AC 19 ms
8,064 KB
testcase_38 AC 18 ms
8,064 KB
testcase_39 AC 18 ms
7,936 KB
testcase_40 AC 20 ms
8,576 KB
testcase_41 AC 19 ms
8,576 KB
testcase_42 AC 19 ms
8,576 KB
testcase_43 AC 19 ms
8,576 KB
testcase_44 AC 19 ms
8,576 KB
testcase_45 AC 19 ms
8,576 KB
testcase_46 AC 19 ms
8,576 KB
testcase_47 AC 19 ms
8,448 KB
testcase_48 AC 19 ms
8,576 KB
testcase_49 AC 19 ms
8,576 KB
testcase_50 AC 20 ms
8,576 KB
testcase_51 AC 19 ms
8,576 KB
testcase_52 AC 19 ms
8,576 KB
testcase_53 AC 19 ms
8,576 KB
testcase_54 AC 20 ms
8,576 KB
testcase_55 AC 20 ms
8,576 KB
testcase_56 AC 19 ms
8,576 KB
testcase_57 AC 20 ms
8,576 KB
testcase_58 AC 19 ms
8,576 KB
testcase_59 AC 19 ms
8,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports)]

fn main() {
    input! {
        t: usize,
    }
    for _ in 0..t {
        input! {
            n: usize, k: usize, x: i64,
            h: [i64; n],
        }
        if h.iter().any(|&hh| (hh - h[0]) % x != 0) {
            println!("No");
            continue;
        }
        let h: Vec<_> = h.iter().map(|hh| (hh - h[0]) / x).collect();
        let mut s = vec![0; n + 1];
        for i in 0..n {
            s[i + 1] = h.get(i + 1).unwrap_or(&0) - h[i];
        }
        for i in 0..=n - k {
            if s[i] < 0 {
                s[i + k] += s[i];
                s[i] = 0;
            }
        }
        for i in (k..=n).rev() {
            if s[i] > 0 {
                s[i - k] += s[i];
                s[i] = 0;
            }
        }
        if s[0] == -s[n] && s[1..n].iter().all(|&s| s == 0) {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}

/*
imos?
l..r += 1
=> l += 1, r -= 1
k = 2
0 -1 0 1 => 0 -1 1 1 -1
k = 3
0 -3 -3 1 3 0 1 2
=> 0 -3 0 4 2 -3 1 1 -2

k = 2
0 1 1 0 => 0 1 0 -1 0

k = 2
0 0 1 1 => 0 0 1 0 -1

k = 1
0 1 2 3 => 0 1 1 1 -3

a 0 .. 0 -a
*/

use proconio::{input, marker::*};
use std::{cmp::Reverse, collections::*};

#[macro_export]
macro_rules! chmax {
    ($a:expr, $b:expr) => {{
        let tmp = $b;
        if $a < tmp {
            $a = tmp;
            true
        } else {
            false
        }
    }};
}

#[macro_export]
macro_rules! chmin {
    ($a:expr, $b:expr) => {{
        let tmp = $b;
        if $a > tmp {
            $a = tmp;
            true
        } else {
            false
        }
    }};
}

#[macro_export]
/// mvec![]
macro_rules! mvec {
    ($val:expr; ()) => {
        $val
    };
    ($val:expr; ($size:expr $(,$rest:expr)*)) => {
        vec![mvec![$val; ($($rest),*)]; $size]
    };
}
0