結果

問題 No.1237 EXP Multiple!
ユーザー どららどらら
提出日時 2020-09-26 02:40:23
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,062 bytes
コンパイル時間 781 ms
コンパイル使用メモリ 140,888 KB
実行使用メモリ 5,732 KB
最終ジャッジ日時 2023-09-10 20:06:42
合計ジャッジ時間 2,190 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 9 ms
4,556 KB
testcase_02 AC 13 ms
5,292 KB
testcase_03 AC 13 ms
5,232 KB
testcase_04 AC 13 ms
5,732 KB
testcase_05 AC 6 ms
4,380 KB
testcase_06 AC 6 ms
4,376 KB
testcase_07 AC 6 ms
4,380 KB
testcase_08 AC 8 ms
4,376 KB
testcase_09 AC 6 ms
4,376 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 AC 6 ms
4,376 KB
testcase_12 AC 8 ms
4,376 KB
testcase_13 AC 9 ms
4,376 KB
testcase_14 AC 8 ms
4,376 KB
testcase_15 AC 9 ms
4,376 KB
testcase_16 AC 9 ms
4,376 KB
testcase_17 AC 8 ms
4,380 KB
testcase_18 AC 9 ms
4,376 KB
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;
use std::str::FromStr;

fn fact(x: i128) -> i128 {
    let mut ret = 1;
    for i in 1..=x {
        ret *= i;
    }
    ret
}

fn calc(n: i64, v: Vec<i64>) -> i64 {
    let mut ret: i128 = 1;
    for i in 0..n {
        let x = v[i as usize] as i128;
        if x == 0 {
            return -1;
        }
        if x >= 4 {
            return 1000_000_007_i64;
        }

        let mut p = 1;
        for _ in 0..fact(x) {
            p *= x;
        }
        ret *= p;
        if ret >= 1000_000_007_i128 {
            return 1000_000_007_i64;
        }
    }
    (1000_000_007_i128 % ret) as i64
}

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let mut itr = s.split_whitespace().map(|x| i64::from_str(x).unwrap());
    let n = itr.next().unwrap();

    s.clear();
    stdin().read_line(&mut s).ok();
    let mut itr = s.split_whitespace().map(|x| i64::from_str(x).unwrap());
    let mut v = Vec::new();
    for _i in 0..n {
        v.push(itr.next().unwrap());
    }

    println!("{}", calc(n, v));
}
0