結果
| 問題 |
No.147 試験監督(2)
|
| コンテスト | |
| ユーザー |
tnoda_
|
| 提出日時 | 2015-02-17 19:03:22 |
| 言語 | Go1.4 (1.4.2) |
| 結果 |
AC
|
| 実行時間 | 387 ms / 2,000 ms |
| コード長 | 1,358 bytes |
| コンパイル時間 | 390 ms |
| コンパイル使用メモリ | 33,796 KB |
| 実行使用メモリ | 6,816 KB |
| 最終ジャッジ日時 | 2024-11-25 00:10:27 |
| 合計ジャッジ時間 | 2,646 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 |
ソースコード
package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
var sc = bufio.NewScanner(os.Stdin)
func next() string {
sc.Split(bufio.ScanWords)
if !sc.Scan() {
panic("could not scan a word from the reader")
}
return sc.Text()
}
func nextInt() int {
i, e := strconv.Atoi(next())
if e != nil {
panic(e)
}
return i
}
func nextLong() int64 {
i, e := strconv.ParseInt(next(), 10, 64)
if e != nil {
panic(e)
}
return i
}
// 10^9 + 7
const P = 1000000007
type mat [2][2]int64
func mul(A, B mat) (C mat) {
for i := 0; i < 2; i++ {
for j := 0; j < 2; j++ {
for k := 0; k < 2; k++ {
C[i][j] = (C[i][j] + A[i][k]*B[k][j]) % P
}
}
}
return
}
func powM(n int64) int64 {
A := [2][2]int64{{1, 1}, {1, 0}}
C := [2][2]int64{{1, 0}, {0, 1}}
for n > 0 {
if (n & 1) == 1 {
C = mul(A, C)
}
n >>= 1
A = mul(A, A)
}
return C[0][0]
}
func decode(s string) (z int64) {
for _, r := range s {
z = (z*10 + int64(r-'0')) % (P - 1)
}
return
}
func pow(x, n int64) (z int64) {
if x == 0 {
return 0
}
z = 1
for n > 0 {
if n&1 > 0 {
z = z * x % P
}
x = x * x % P
n >>= 1
}
return
}
func pat(c int64, d string) int64 {
return pow(powM(c+1), decode(d))
}
func main() {
N := nextInt()
res := int64(1)
for i := 0; i < N; i++ {
C, D := nextLong(), next()
res = res * pat(C, D) % P
}
fmt.Println(res)
}
tnoda_