結果

問題 No.1501 酔歩
ユーザー chineristACchineristAC
提出日時 2021-05-08 02:19:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 1,014 bytes
コンパイル時間 477 ms
コンパイル使用メモリ 87,148 KB
実行使用メモリ 98,392 KB
最終ジャッジ日時 2023-10-13 21:07:28
合計ジャッジ時間 13,637 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
74,528 KB
testcase_01 AC 113 ms
74,596 KB
testcase_02 AC 112 ms
74,652 KB
testcase_03 AC 112 ms
74,240 KB
testcase_04 AC 110 ms
74,440 KB
testcase_05 AC 169 ms
95,540 KB
testcase_06 AC 159 ms
92,760 KB
testcase_07 AC 166 ms
95,648 KB
testcase_08 AC 131 ms
80,032 KB
testcase_09 AC 163 ms
94,900 KB
testcase_10 AC 135 ms
81,552 KB
testcase_11 AC 158 ms
92,320 KB
testcase_12 AC 152 ms
89,516 KB
testcase_13 AC 112 ms
74,732 KB
testcase_14 AC 114 ms
74,660 KB
testcase_15 AC 114 ms
74,256 KB
testcase_16 AC 114 ms
74,760 KB
testcase_17 AC 117 ms
74,524 KB
testcase_18 AC 115 ms
74,428 KB
testcase_19 AC 114 ms
74,580 KB
testcase_20 AC 113 ms
74,376 KB
testcase_21 AC 112 ms
74,672 KB
testcase_22 AC 176 ms
98,392 KB
testcase_23 AC 178 ms
98,056 KB
testcase_24 AC 179 ms
98,156 KB
testcase_25 AC 180 ms
98,012 KB
testcase_26 AC 181 ms
98,088 KB
testcase_27 AC 191 ms
98,240 KB
testcase_28 AC 179 ms
98,116 KB
testcase_29 AC 186 ms
98,092 KB
testcase_30 AC 184 ms
97,972 KB
testcase_31 AC 186 ms
98,224 KB
testcase_32 AC 188 ms
98,144 KB
testcase_33 AC 182 ms
98,272 KB
testcase_34 AC 178 ms
98,116 KB
testcase_35 AC 179 ms
98,148 KB
testcase_36 AC 178 ms
98,168 KB
testcase_37 AC 177 ms
98,060 KB
testcase_38 AC 186 ms
98,088 KB
testcase_39 AC 188 ms
98,080 KB
testcase_40 AC 174 ms
97,900 KB
testcase_41 AC 191 ms
98,148 KB
testcase_42 AC 160 ms
97,992 KB
testcase_43 AC 113 ms
74,472 KB
testcase_44 AC 113 ms
74,528 KB
testcase_45 AC 158 ms
97,888 KB
testcase_46 AC 159 ms
97,896 KB
testcase_47 AC 158 ms
98,176 KB
testcase_48 AC 171 ms
98,184 KB
testcase_49 AC 167 ms
98,320 KB
testcase_50 AC 166 ms
98,052 KB
testcase_51 AC 168 ms
97,940 KB
testcase_52 AC 169 ms
98,196 KB
testcase_53 AC 113 ms
74,796 KB
testcase_54 AC 111 ms
74,736 KB
testcase_55 AC 112 ms
74,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import log,gcd

input = lambda :sys.stdin.buffer.readline()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

N,K = mi()
A = li()
n = N

if N==1:
    print("1/1")
    exit()

dp = [[(0,1),(0,1)] for i in range(n)]
dp[1][1] = (1,1)
for i in range(2,n):
    p,q = A[i-2],A[i-2]+A[i]

    a,b = dp[i-1][1]
    c,d = dp[i-2][1]
    c,d = c*p,d*q

    a,b,c,d = a*d,b*d,c*b,b*d
    p,q = A[i-2],A[i-2]+A[i]

    e,f = (a-c)*q,(q-p)*b
    g = gcd(e,f)
    dp[i][1] = (e//g,f//g)

a,b = dp[n-1][0]
c,d = dp[n-1][1]

"""
1 = a/b + c/d * dp[1]
dp[1] = -a*d/b*c
"""

e,f = (b-a)*d,b*c
g = gcd(e,f)
e //= g
f //= g

a,b = dp[K-1][0]
c,d = dp[K-1][1]

"""
p/q = a/b + c/d * e/f
    = adf/bdf + bce/bdf
    = (a*d*f+b*c*e)/(b*d*f)
"""

p,q = a*d*f+b*c*e,b*d*f
if p<0:
    p,q = -p,-q
g = gcd(p,q)
if p:
    print("{}/{}".format(p//g,q//g))
else:
    print(0)
0