結果

問題 No.1084 積の積
ユーザー tonyu0tonyu0
提出日時 2020-06-20 00:45:05
言語 Rust
(1.77.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,397 bytes
コンパイル時間 4,559 ms
コンパイル使用メモリ 146,100 KB
実行使用メモリ 5,184 KB
最終ジャッジ日時 2023-09-16 16:19:47
合計ジャッジ時間 2,183 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 25 ms
4,552 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 25 ms
4,544 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 6 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 5 ms
4,380 KB
testcase_13 AC 9 ms
4,868 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 9 ms
5,184 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 7 ms
4,384 KB
testcase_19 AC 9 ms
4,916 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 5 ms
4,376 KB
testcase_24 AC 5 ms
4,380 KB
testcase_25 AC 9 ms
4,928 KB
testcase_26 AC 8 ms
4,584 KB
testcase_27 AC 8 ms
4,648 KB
testcase_28 AC 8 ms
4,612 KB
testcase_29 AC 8 ms
4,672 KB
testcase_30 AC 8 ms
4,656 KB
testcase_31 AC 8 ms
4,612 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `std::cmp::*`
 --> Main.rs:1:5
  |
1 | use std::cmp::*;
  |     ^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: 1 warning emitted

ソースコード

diff #

use std::cmp::*;
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();

    if let Some(x) = a.iter().find(|&&x| x == 0) {
        println!("{}", x);
        return;
    }

    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 t = 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;
        }
        s[l] += 1;
        s[r] -= 1;
        t[l] = (r - l) as i64;

        if l == r {
            r += 1;
        }
        now /= a[l];
    }

    for i in 0..n {
        s[i + 1] += s[i];
    }
    for i in 1..n {
        s[i - 1] -= t[i];
    }
    for i in (1..=n).rev() {
        s[i - 1] += s[i];
    }

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