結果
問題 | No.1706 Many Bus Stops (hard) |
ユーザー | mkawa2 |
提出日時 | 2021-10-08 23:50:41 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 51 ms / 2,000 ms |
コード長 | 1,530 bytes |
コンパイル時間 | 506 ms |
コンパイル使用メモリ | 82,464 KB |
実行使用メモリ | 63,460 KB |
最終ジャッジ日時 | 2024-07-23 08:20:20 |
合計ジャッジ時間 | 3,607 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 49 ms
62,004 KB |
testcase_01 | AC | 48 ms
63,392 KB |
testcase_02 | AC | 50 ms
62,556 KB |
testcase_03 | AC | 48 ms
62,288 KB |
testcase_04 | AC | 48 ms
62,312 KB |
testcase_05 | AC | 49 ms
63,276 KB |
testcase_06 | AC | 50 ms
62,884 KB |
testcase_07 | AC | 49 ms
62,820 KB |
testcase_08 | AC | 49 ms
61,868 KB |
testcase_09 | AC | 48 ms
62,348 KB |
testcase_10 | AC | 48 ms
62,488 KB |
testcase_11 | AC | 49 ms
62,604 KB |
testcase_12 | AC | 49 ms
63,140 KB |
testcase_13 | AC | 49 ms
62,828 KB |
testcase_14 | AC | 49 ms
61,824 KB |
testcase_15 | AC | 48 ms
63,032 KB |
testcase_16 | AC | 51 ms
61,816 KB |
testcase_17 | AC | 49 ms
62,088 KB |
testcase_18 | AC | 48 ms
62,804 KB |
testcase_19 | AC | 49 ms
62,944 KB |
testcase_20 | AC | 48 ms
62,508 KB |
testcase_21 | AC | 49 ms
63,080 KB |
testcase_22 | AC | 48 ms
62,392 KB |
testcase_23 | AC | 50 ms
63,208 KB |
testcase_24 | AC | 48 ms
62,184 KB |
testcase_25 | AC | 49 ms
63,436 KB |
testcase_26 | AC | 48 ms
62,300 KB |
testcase_27 | AC | 49 ms
63,460 KB |
testcase_28 | AC | 47 ms
62,688 KB |
testcase_29 | AC | 47 ms
61,952 KB |
testcase_30 | AC | 47 ms
61,488 KB |
testcase_31 | AC | 50 ms
61,884 KB |
testcase_32 | AC | 50 ms
62,536 KB |
testcase_33 | AC | 49 ms
63,232 KB |
testcase_34 | AC | 48 ms
62,128 KB |
testcase_35 | AC | 48 ms
62,028 KB |
testcase_36 | AC | 49 ms
63,412 KB |
testcase_37 | AC | 48 ms
61,628 KB |
testcase_38 | AC | 49 ms
63,088 KB |
testcase_39 | AC | 48 ms
62,228 KB |
testcase_40 | AC | 48 ms
63,004 KB |
testcase_41 | AC | 48 ms
62,416 KB |
testcase_42 | AC | 48 ms
61,948 KB |
ソースコード
import sys sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] dij = [(0, 1), (1, 0), (0, -1), (-1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = 10**19 # md = 998244353 md = 10**9+7 def dot(aa, bb): h = len(aa) w = len(bb[0]) res = [[0]*w for _ in range(h)] for i, row in enumerate(aa): for j, col in enumerate(zip(*bb)): v = 0 # for a, b in zip(row, col): v += a*b # res[i][j] = v%md for a, b in zip(row, col): v += a*b%md res[i][j] = v%md return res def matpow(e): n = 4 res = [[1 if i == j else 0 for j in range(n)] for i in range(n)] i = 0 while e: if e & 1: res = dot(res, mm[i]) e >>= 1 i += 1 return res c, n, m = LI() inv = pow(c, md-2, md) mat = [[0, 0, 0, inv] , [0, 0, inv*(c-1)%md, inv*(c-2)%md] , [1, 0, inv, 0] , [0, 1, 0, inv]] lim = 10**9+5 i = 1 mm = [] while i < lim: mm.append(mat) mat = dot(mat, mat) i <<= 1 p = matpow(n)[2][2]%md ans = (1-pow(1-p, m, md))%md print(ans)