結果

問題 No.1495 パンの仕入れ
ユーザー penguinmanpenguinman
提出日時 2021-04-25 02:51:07
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,212 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 87,416 KB
実行使用メモリ 85,684 KB
最終ジャッジ日時 2023-09-17 14:00:52
合計ジャッジ時間 17,132 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,332 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 275 ms
78,696 KB
testcase_13 AC 270 ms
78,564 KB
testcase_14 AC 277 ms
78,708 KB
testcase_15 AC 271 ms
78,608 KB
testcase_16 AC 275 ms
78,508 KB
testcase_17 AC 269 ms
78,424 KB
testcase_18 AC 277 ms
78,692 KB
testcase_19 AC 272 ms
78,800 KB
testcase_20 AC 269 ms
78,208 KB
testcase_21 AC 273 ms
78,904 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 188 ms
80,416 KB
testcase_25 AC 186 ms
80,480 KB
testcase_26 AC 186 ms
80,628 KB
testcase_27 AC 184 ms
80,736 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 269 ms
78,232 KB
testcase_31 AC 261 ms
78,600 KB
testcase_32 AC 267 ms
78,240 KB
testcase_33 AC 266 ms
78,468 KB
testcase_34 AC 269 ms
78,496 KB
testcase_35 AC 272 ms
78,564 KB
testcase_36 AC 268 ms
78,588 KB
testcase_37 AC 269 ms
78,544 KB
testcase_38 AC 267 ms
78,644 KB
testcase_39 AC 267 ms
78,360 KB
testcase_40 AC 257 ms
78,500 KB
testcase_41 AC 255 ms
78,312 KB
testcase_42 AC 255 ms
78,656 KB
testcase_43 AC 253 ms
78,460 KB
testcase_44 AC 256 ms
78,740 KB
testcase_45 AC 73 ms
71,496 KB
testcase_46 WA -
testcase_47 AC 73 ms
71,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())
inf = int(2e18)
for _ in range(T):
    N, M, K = map(int, input().split())
    x = [0]*M
    y = [0]*M
    for i in range(M):
        x[i], y[i] = map(int, input().split())
    cnt = [0]*N
    mem = [0]*N
    for i in range(M):
        x[i] -= 1
        cnt[x[i]] += 2
        # (x-y)^2-(x-(y-1))^2 = 2x-2y-1
        mem[x[i]] -= 2*y[i]+1
    left = -inf
    right = inf
    while left+1 < right:
        mid = (right+left)//2
        cnt2 = 0
        for i in range(N):
            if cnt[i] == 0:
                if 0 <= mid:
                    cnt2 += inf
            else:
                # ax+mem[i] ≤ mid
                # ax ≤ mid-mem[i]
                cnt2 += max(0, (mid-mem[i])//cnt[i])
            if cnt2 > K:
                break
        if cnt2 < K:
            left = mid
        else:
            right = mid
    ans = 0
    flag = False
    num = [0]*N
    cnt2 = 0
    for i in range(N):
        if cnt[i] == 0:
            flag = True
        else:
            num[i] = max(0, (left-mem[i])//cnt[i])
            cnt2 += num[i]
    for i in range(M):
        ans += (num[x[i]]-y[i])*(num[x[i]]-y[i])
    if flag:
        cnt2 = K
    ans += (K-cnt2)*right
    print(ans)
0