結果

問題 No.1084 積の積
ユーザー tonyu0tonyu0
提出日時 2020-06-20 00:42:25
言語 Rust
(1.77.0)
結果
RE  
実行時間 -
コード長 1,296 bytes
コンパイル時間 675 ms
コンパイル使用メモリ 148,688 KB
実行使用メモリ 5,188 KB
最終ジャッジ日時 2023-09-16 16:19:19
合計ジャッジ時間 2,246 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 0 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 24 ms
4,564 KB
testcase_05 RE -
testcase_06 AC 25 ms
4,564 KB
testcase_07 RE -
testcase_08 AC 1 ms
4,376 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 AC 8 ms
4,940 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 9 ms
5,188 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 7 ms
4,408 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,380 KB
testcase_23 AC 5 ms
4,376 KB
testcase_24 AC 5 ms
4,380 KB
testcase_25 AC 9 ms
4,944 KB
testcase_26 AC 9 ms
4,676 KB
testcase_27 AC 8 ms
4,692 KB
testcase_28 AC 8 ms
4,700 KB
testcase_29 AC 8 ms
4,688 KB
testcase_30 AC 8 ms
4,636 KB
testcase_31 AC 8 ms
4,684 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();

    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