結果

問題 No.2207 pCr検査
ユーザー dachengzdachengz
提出日時 2023-02-06 12:47:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,046 ms / 3,000 ms
コード長 1,218 bytes
コンパイル時間 510 ms
コンパイル使用メモリ 87,068 KB
実行使用メモリ 180,052 KB
最終ジャッジ日時 2023-09-18 00:36:02
合計ジャッジ時間 15,720 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,484 KB
testcase_01 AC 71 ms
71,508 KB
testcase_02 AC 507 ms
122,432 KB
testcase_03 AC 418 ms
107,880 KB
testcase_04 AC 393 ms
107,592 KB
testcase_05 AC 617 ms
135,180 KB
testcase_06 AC 258 ms
90,116 KB
testcase_07 AC 314 ms
97,400 KB
testcase_08 AC 285 ms
92,868 KB
testcase_09 AC 500 ms
121,516 KB
testcase_10 AC 141 ms
79,764 KB
testcase_11 AC 476 ms
116,828 KB
testcase_12 AC 434 ms
122,932 KB
testcase_13 AC 312 ms
106,512 KB
testcase_14 AC 156 ms
84,248 KB
testcase_15 AC 344 ms
108,340 KB
testcase_16 AC 298 ms
103,332 KB
testcase_17 AC 328 ms
108,120 KB
testcase_18 AC 190 ms
89,040 KB
testcase_19 AC 222 ms
92,560 KB
testcase_20 AC 179 ms
86,716 KB
testcase_21 AC 500 ms
135,492 KB
testcase_22 AC 1,046 ms
180,052 KB
testcase_23 AC 1,036 ms
180,016 KB
testcase_24 AC 134 ms
79,716 KB
testcase_25 AC 313 ms
99,916 KB
testcase_26 AC 240 ms
89,944 KB
testcase_27 AC 306 ms
96,988 KB
testcase_28 AC 675 ms
142,820 KB
testcase_29 AC 680 ms
142,864 KB
testcase_30 AC 684 ms
142,980 KB
testcase_31 AC 664 ms
142,832 KB
権限があれば一括ダウンロードができます

ソースコード

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(lo1, hi2 + 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