結果

問題 No.2955 Pizza Delivery Plan
ユーザー Thania Montana
提出日時 2025-08-12 15:08:30
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 2,299 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 12,032 KB
実行使用メモリ 10,240 KB
最終ジャッジ日時 2025-08-12 15:08:33
合計ジャッジ時間 2,376 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-

import sys

def solve():
    """
    Solves a single test case.
    """
    try:
        line = sys.stdin.readline()
        if not line:
            return
        N, K = map(int, line.split())
    except (IOError, ValueError):
        return

    # The problem is equivalent to partitioning a total length of N into K integer parts (distances)
    # such that the maximum part is minimized.
    # Let the distances be d_1, d_2, ..., d_K.
    # We have sum(d_i) = N. We want to minimize max(d_i).
    # To make the maximum as small as possible, the distances should be as equal as possible.
    
    # Using integer division, we can express N as N = q*K + r,
    # where q = N // K is the quotient and r = N % K is the remainder.
    
    # This means we can have a base distance of q for all K segments.
    # The total length covered would be q * K.
    # The remaining length is N - q*K = r.
    
    # This remainder 'r' must be distributed among the K segments.
    # To keep the maximum distance minimal, we add 1 to 'r' of the segments.
    
    # This results in:
    # - r segments of length q + 1
    # - K - r segments of length q
    
    # Case 1: The remainder r is 0.
    # This means N is perfectly divisible by K.
    if N % K == 0:
        # All K distances can be equal to N // K.
        # The maximum distance D is N // K.
        D = N // K
        # All K pairs of servers are separated by this distance.
        X = K
        print(D, X)
    else:
        # Case 2: The remainder r is greater than 0.
        # The distances will be a mix of q and q+1.
        q = N // K
        r = N % K
        
        # The maximum distance D will be q + 1.
        D = q + 1
        # The number of pairs separated by this maximum distance is r.
        # This is also the minimum possible number of pairs with this distance.
        X = r
        print(D, X)

def main():
    """
    Main function to handle multiple test cases.
    """
    try:
        T_str = sys.stdin.readline()
        if not T_str:
            return
        T = int(T_str)
        for _ in range(T):
            solve()
    except (IOError, ValueError):
        # Handle potential empty lines or invalid input at the end of the file
        pass

if __name__ == "__main__":
    main()
0