結果

問題 No.1618 Convolution?
ユーザー koba-e964koba-e964
提出日時 2021-08-20 22:19:53
言語 Rust
(1.77.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 1,908 bytes
コンパイル時間 2,138 ms
コンパイル使用メモリ 163,560 KB
実行使用メモリ 9,728 KB
最終ジャッジ日時 2024-04-22 05:01:56
合計ジャッジ時間 7,401 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 34 ms
7,936 KB
testcase_03 AC 41 ms
9,088 KB
testcase_04 AC 33 ms
6,784 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 43 ms
8,320 KB
testcase_07 AC 44 ms
8,192 KB
testcase_08 AC 33 ms
6,912 KB
testcase_09 AC 52 ms
9,472 KB
testcase_10 AC 36 ms
7,296 KB
testcase_11 AC 49 ms
9,216 KB
testcase_12 AC 51 ms
9,728 KB
testcase_13 AC 50 ms
9,728 KB
testcase_14 AC 51 ms
9,728 KB
testcase_15 AC 49 ms
9,728 KB
testcase_16 AC 51 ms
9,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::cmp::*;
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, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {($($format:tt)*) => (let _ = write!(out,$($format)*););}
    #[allow(unused)]
    macro_rules! putvec {
        ($v:expr) => {
            for i in 0..$v.len() {
                puts!("{}{}", $v[i], if i + 1 == $v.len() {"\n"} else {" "});
            }
        }
    }
    input! {
        n: usize,
        a: [i64; n],
        b: [i64; n],
    }
    let mut acc = vec![0; n + 1];
    for i in 0..n {
        acc[i + 1] = acc[i] + a[i] + b[i];
    }
    let mut ans = vec![0; 2 * n];
    for i in 1..2 * n {
        let hi = min(i, n);
        let lo = max(i, n) - n;
        ans[i] = ans[i - 1] + acc[hi] - acc[lo];
        if i > n {
            ans[i] -= (acc[lo] - acc[lo - 1]) * n as i64;
        }
    }
    putvec!(ans);
}
0