結果

問題 No.2207 pCr検査
ユーザー dachengzdachengz
提出日時 2023-02-06 12:42:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,218 bytes
コンパイル時間 665 ms
コンパイル使用メモリ 87,364 KB
実行使用メモリ 180,132 KB
最終ジャッジ日時 2023-09-18 00:31:51
合計ジャッジ時間 16,854 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 76 ms
71,404 KB
testcase_02 AC 536 ms
122,416 KB
testcase_03 AC 414 ms
107,680 KB
testcase_04 AC 417 ms
107,572 KB
testcase_05 AC 634 ms
135,072 KB
testcase_06 AC 267 ms
90,240 KB
testcase_07 AC 323 ms
97,200 KB
testcase_08 AC 284 ms
92,836 KB
testcase_09 AC 528 ms
121,508 KB
testcase_10 AC 140 ms
79,584 KB
testcase_11 AC 493 ms
116,816 KB
testcase_12 AC 440 ms
122,928 KB
testcase_13 AC 317 ms
106,376 KB
testcase_14 AC 155 ms
84,256 KB
testcase_15 AC 341 ms
108,432 KB
testcase_16 AC 302 ms
103,568 KB
testcase_17 AC 336 ms
107,964 KB
testcase_18 AC 199 ms
89,024 KB
testcase_19 AC 229 ms
92,488 KB
testcase_20 AC 182 ms
86,748 KB
testcase_21 AC 521 ms
135,520 KB
testcase_22 AC 1,077 ms
180,132 KB
testcase_23 AC 1,084 ms
179,936 KB
testcase_24 AC 118 ms
79,204 KB
testcase_25 AC 276 ms
99,912 KB
testcase_26 AC 205 ms
90,036 KB
testcase_27 AC 309 ms
97,092 KB
testcase_28 WA -
testcase_29 AC 697 ms
143,156 KB
testcase_30 AC 694 ms
142,936 KB
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import log, lgamma

def deg(n, p):
    ret = 0
    n //= p
    while n:
        ret += n
        n //= p
    return ret

def isqrt(n):
    if n <= 0:
        return 0

    x = int((n ** 0.5) * (1 + 1e-14))
    while True:
        y = (x + n // x) // 2
        if y >= x:
            return x
        x = y

k = int(input())
pe = []
for _ in range(k):
    pe.append([int(x) for x in input().split()])

P = pe[-1][0]
P1 = P + 1
needlog = 0.0
for p, e in pe:
    if e > deg(P, p):
        print(-1, -1)
        exit
    needlog += log(p) * e
lgP = lgamma(P1)

lo1, hi1 = 1, P // 2
if lgP - lgamma(hi1) - lgamma(P1 - hi1) - needlog < -1e-6:
    print(-1, -1)
    exit
while hi1 - lo1 > 1:
    md = lo1 + (hi1 - lo1) // 2
    lgcomb = lgP - lgamma(md + 1) - lgamma(P1 - md)
    if lgcomb - needlog < -1e-6:
        lo1 = md
    else:
        hi1 = md

lo2, hi2 = 1, P // 2
while hi2 - lo2 > 1:
    md = lo2 + (hi2 - lo2) // 2
    lgcomb = lgP - lgamma(md + 1) - lgamma(P1 - md)
    if lgcomb - needlog > 1e-6:
        hi2 = md
    else:
        lo2 = md

for r in range(hi1, lo2 + 1):
    if all(deg(P, p) - deg(r, p) - deg(P - r, p) == e for p, e in pe):
        print(P, r)
        exit
else:
    print(-1, -1)
0