結果

問題 No.1237 EXP Multiple!
ユーザー m0ch1m0ch1m0ch1m0ch1
提出日時 2020-09-25 22:44:28
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 921 bytes
コンパイル時間 11,811 ms
コンパイル使用メモリ 207,800 KB
実行使用メモリ 8,768 KB
最終ジャッジ日時 2023-09-10 15:57:13
合計ジャッジ時間 15,614 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func permutation(n int, k int) int {
	v := 1
	if 0 < k && k <= n {
		for i := 0; i < k; i++ {
			v *= (n - i) % int(math.Pow10(9)+7)
		}
	} else if k > n {
		v = 0
	}
	return v
}

func factorial(n int) int {
	return permutation(n, n-1)
}

func combination(n int, k int) int {
	return permutation(n, k) / factorial(k)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var N int
	fmt.Scan(&N)

	sc.Split(bufio.ScanWords)
	A := make([]int, N)
	var flag int
	for i := 0; i < N; i++ {
		A[i] = nextInt()
		if A[i] == 0 {
			flag = 1
		}
	}

	var ans int = 1
	if flag == 1 {
		fmt.Println("-1")
	} else {
		for i := 0; i < N; i++ {
			ans *= int(math.Pow(float64(A[i]), float64(factorial(A[i])))) % int(math.Pow10(9)+7)
		}
	}

	fmt.Println(ans)
}
0