結果

問題 No.180 美しいWhitespace (2)
ユーザー yuushi narazaki
提出日時 2025-03-07 16:31:20
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 982 bytes
コンパイル時間 314 ms
コンパイル使用メモリ 82,092 KB
実行使用メモリ 75,440 KB
最終ジャッジ日時 2025-03-07 16:31:23
合計ジャッジ時間 3,384 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 4
other WA * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

def calculate_splendor(tab_width, n, lines):
    min_width = float('inf')
    max_width = -float('inf')
    
    for spaces, tabs in lines:
        width = spaces + tabs * tab_width
        min_width = min(min_width, width)
        max_width = max(max_width, width)
    
    return max_width - min_width

def solve(n, lines):
    left, right = 1, 100000  # 1 <= tab_width <= 100000と仮定
    
    # 三分探索を100回行う
    for _ in range(100):
        c1 = (2 * left + right) // 3
        c2 = (left + 2 * right) // 3
        
        if calculate_splendor(c1, n, lines) < calculate_splendor(c2, n, lines):
            right = c2
        else:
            left = c1
    
    # 最終的に求めたタブ幅での最小の醜さ
    return calculate_splendor(left, n, lines)

# 入力の処理
n = int(input())  # 行数
lines = []
for _ in range(n):
    spaces, tabs = map(int, input().split())
    lines.append((spaces, tabs))

# 結果を出力
print(solve(n, lines))
0