結果

問題 No.1237 EXP Multiple!
ユーザー m0ch1m0ch1m0ch1m0ch1
提出日時 2020-09-25 23:53:31
言語 Go
(1.22.1)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 886 bytes
コンパイル時間 12,000 ms
コンパイル使用メモリ 212,932 KB
実行使用メモリ 5,556 KB
最終ジャッジ日時 2023-09-10 17:32:29
合計ジャッジ時間 13,371 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 40 ms
4,380 KB
testcase_02 AC 55 ms
4,380 KB
testcase_03 AC 56 ms
5,556 KB
testcase_04 AC 23 ms
5,556 KB
testcase_05 AC 10 ms
5,552 KB
testcase_06 AC 16 ms
5,556 KB
testcase_07 AC 11 ms
5,552 KB
testcase_08 AC 14 ms
5,552 KB
testcase_09 AC 11 ms
5,552 KB
testcase_10 AC 11 ms
5,552 KB
testcase_11 AC 17 ms
5,552 KB
testcase_12 AC 10 ms
5,552 KB
testcase_13 AC 11 ms
5,552 KB
testcase_14 AC 11 ms
5,556 KB
testcase_15 AC 11 ms
5,552 KB
testcase_16 AC 11 ms
5,552 KB
testcase_17 AC 11 ms
5,552 KB
testcase_18 AC 11 ms
5,552 KB
testcase_19 AC 11 ms
5,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

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

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

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)
	for i := 0; i < N; i++ {
		A[i] = nextInt()
	}

	sort.Sort(sort.IntSlice(A))

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