結果
| 問題 | 
                            No.1237 EXP Multiple!
                             | 
                    
| コンテスト | |
| ユーザー | 
                             Strorkis
                         | 
                    
| 提出日時 | 2020-09-25 23:28:13 | 
| 言語 | Rust  (1.83.0 + proconio)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 14 ms / 2,000 ms | 
| コード長 | 1,383 bytes | 
| コンパイル時間 | 12,412 ms | 
| コンパイル使用メモリ | 378,012 KB | 
| 実行使用メモリ | 5,760 KB | 
| 最終ジャッジ日時 | 2024-06-28 08:39:40 | 
| 合計ジャッジ時間 | 13,746 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 19 | 
ソースコード
macro_rules! read_line_to_tuple {
    ( $( $t:ty ),* ) => {{
        let mut input = String::new();
        std::io::stdin().read_line(&mut input).unwrap();
        let mut iter = input.split_whitespace();
        ( $( iter.next().unwrap().parse::<$t>().unwrap() ),* )
    }};
}
macro_rules! read_line_to_collection {
    ( $t:ty ) => {{
        let mut input = String::new();
        std::io::stdin().read_line(&mut input).unwrap();
        let iter = input.split_whitespace();
        iter.map(|x| x.parse().unwrap()).collect::<$t>()
    }};
}
const MOD: i64 = 1_000_000_007;
fn main() {
    let n = read_line_to_tuple!(usize);
    let a = read_line_to_collection!(Vec<i64>);
    let min = *a.iter().min().unwrap();
    if min == 0 {
        return println!("-1");
    }
    let max = *a.iter().max().unwrap();
    if max >= 4 {
        return println!("{}", MOD);
    }
    let pow = |mut a: i64, mut n: usize| -> i64 {
        let mut res = 1;
        while n > 0 {
            if n & 1 > 0 {
                res = res * a % MOD;
            }
            a = a * a % MOD;
            n >>= 1;
        }
        res
    };
    let mut ans = 1;
    for i in 0..n {
        let k = (1..=a[i]).fold(1, |acc, x| acc * x);
        ans = ans * pow(a[i], k as usize);
        if ans > MOD {
            return println!("{}", MOD);
        }
    }
    println!("{}", MOD % ans);
}
            
            
            
        
            
Strorkis