結果
| 問題 |
No.147 試験監督(2)
|
| コンテスト | |
| ユーザー |
6soukiti29
|
| 提出日時 | 2017-09-16 16:25:46 |
| 言語 | Nim (2.2.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,080 bytes |
| コンパイル時間 | 3,137 ms |
| コンパイル使用メモリ | 67,356 KB |
| 実行使用メモリ | 16,824 KB |
| 最終ジャッジ日時 | 2024-06-30 03:12:05 |
| 合計ジャッジ時間 | 9,409 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 1 -- * 3 |
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'sequtils' [UnusedImport]
ソースコード
import sequtils,strutils,strscans
const
m : int64 = 1_000_000_007
var
N = stdin.readline.parseInt
ans, c : int64
s,d,cs : string
proc ctoi(c : char) : int =
return ord(c) - ord('0')
proc pows(i : int64, s : string) : int64 =
if s == "0" or s == "":
return 1
elif s == "1":
return i mod m
elif (s[^1].ctoi and 1) == 1:
return (i * pows(i, s[0..<s.high] & $(s[^1].ctoi - 1))) mod m
else:
var
s2 : string = ""
flag : bool
for j in 0..s.high:
var k : string
if flag == true:
k = $((10 + s[j].ctoi) div 2)
else:
k = $(s[j].ctoi div 2)
if (s[j].ctoi and 1) == 1:
flag = true
else:
flag = false
if k != "0" or j != 0:
s2 &= k
return pows((i * i) mod m, s2) mod m
type
Matrix[H,W: static[int]] =
array[1..H,array[1..W,int64]]
proc `+`[H,W](a,b:Matrix[H,W]):Matrix[H,W] =
for i in 1..high(a):
for j in 1..high(a[0]):
result[i][j] = a[i][j] + b[i][j]
proc `*`[Ha,Wa,Wb](a:Matrix[Ha,Wa],b:Matrix[Wa,Wb]):Matrix[Ha,Wb] =
var k : int64
for i in 1.. Ha:
for j in 1..Wb:
k = 0
for ai in 1..Wa:
k = (k + a[i][ai] * b[ai][j]) mod m
result[i][j] = k
proc powMatrix[W,H](a : Matrix[W,H], n : int64):Matrix[W,H] =
if n == 1:
return a
if n mod 2 == 0:
return powMatrix(a * a,n div 2)
else:
return powMatrix(a * a,n div 2) * a
proc printMatrix(A: Matrix)=
for a in A:
echo a.join(", ")
proc fib(n : int64): int64 =
if n == 0:
return 0
var
A : Matrix[2,2] = [[1.int64,1.int64],[1.int64,0.int64]]
return (powMatrix(A,n))[2][1] mod m
ans = 1
for n in 1..N:
s = stdin.readline
discard scanf(s, "$* $*", cs, d)
c = cs.parseBiggestInt
ans = (ans * pows(fib(c + 2) , d)) mod m
echo ans
6soukiti29