結果

問題 No.1495 パンの仕入れ
ユーザー penguinmanpenguinman
提出日時 2021-04-25 02:53:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,227 bytes
コンパイル時間 127 ms
コンパイル使用メモリ 10,924 KB
実行使用メモリ 13,080 KB
最終ジャッジ日時 2023-09-17 14:00:50
合計ジャッジ時間 4,480 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
12,752 KB
testcase_01 AC 16 ms
8,180 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
権限があれば一括ダウンロードができます

ソースコード

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 and right > 0:
        cnt2 = K
    ans += (K-cnt2)*right
    print(ans)
0