結果

問題 No.1336 Union on Blackboard
ユーザー StrorkisStrorkis
提出日時 2021-01-15 21:46:29
言語 Rust
(1.77.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,620 bytes
コンパイル時間 11,434 ms
コンパイル使用メモリ 377,996 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-04 23:19:01
合計ジャッジ時間 12,782 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::{Read, Write};

struct Scanner<R> { bytes: std::io::Bytes<R>, buf: Vec<u8> }
 
impl<R: Read> Scanner<R> {
    fn new(r: R) -> Scanner<R> {
        Scanner { bytes: r.bytes(), buf: Vec::new() }
    }
  
    fn next(&mut self) -> &str {
        self.buf = {
            self.bytes.by_ref().map(|b| b.unwrap())
                .skip_while(|b| b.is_ascii_whitespace())
                .take_while(|b| !b.is_ascii_whitespace())
                .collect::<Vec<_>>()
        };
        unsafe { std::str::from_utf8_unchecked(&self.buf) }
    }
}

macro_rules! scan {
    ($sc:expr, [$t:tt; $n:expr]) => (
        (0..$n).map(|_| scan!($sc, $t)).collect::<Vec<_>>()
    );
    ($sc:expr, ($($t:tt),*)) => (($(scan!($sc, $t)),*));
    ($sc:expr, Usize1) => (scan!($sc, usize) - 1);
    ($sc:expr, Bytes) => ($sc.next().bytes().collect::<Vec<_>>());
    ($sc:expr, Chars) => ($sc.next().chars().collect::<Vec<_>>());
    ($sc:expr, $t:ty) => ($sc.next().parse::<$t>().unwrap());
}

fn run<R: Read, W: Write>(mut sc: Scanner<R>, mut wr: W) {
    const MOD: i64 = 1_000_000_007;
    for _ in 0..scan!(sc, usize) {
        let n = scan!(sc, usize);
        let a = scan!(sc, [i64; n]);
        writeln!(
            wr,
            "{}",
            a.into_iter().fold(1, |acc, val| acc * (val + 1) % MOD) - 1
        ).ok();
    }
}

fn main() {
    let (stdin, stdout) = (std::io::stdin(), std::io::stdout());
    let sc = Scanner::new(std::io::BufReader::new(stdin.lock()));
    let wr = std::io::BufWriter::new(stdout.lock());
    run(sc, wr);
}

/*
    a b c
    (ab + a + b) c
    abc + ac + bc + ab + a + b + c
*/
0