結果

問題 No.1084 積の積
ユーザー tonyu0tonyu0
提出日時 2020-06-20 00:06:22
言語 Rust
(1.77.0)
結果
TLE  
実行時間 -
コード長 1,090 bytes
コンパイル時間 922 ms
コンパイル使用メモリ 149,924 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-16 16:10:47
合計ジャッジ時間 8,148 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

use std::io::*;
const MOD: i64 = 1_000_000_007;

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

    let mp = |mut x: i64, mut e: i64| -> i64 {
        let mut res = 1;
        while e > 0 {
            if e & 1 == 1 {
                res = res * x % MOD;
            }
            x = x * x % MOD;
            e >>= 1;
        }
        res
    };

    let mut s = vec![0i64; n + 1];
    let mut r = 0;
    let mut now = 1;
    for l in 0..n {
        while r < n && now * a[r] < 1_000_000_000 {
            now *= a[r];
            r += 1;
        }
        for i in 0..r - l {
            s[l + i] += (r - l - i) as i64;
        }
        if l == r {
            r += 1;
        }
        now /= a[l];
    }

    let mut ans = 1;
    for i in 0..n {
        ans = ans * mp(a[i], s[i]) % MOD;
    }
    println!("{}", ans);
}
0