結果

問題 No.625 ソンタクロース
ユーザー しらっ亭
提出日時 2017-12-25 00:08:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,313 ms / 4,000 ms
コード長 968 bytes
コンパイル時間 210 ms
コンパイル使用メモリ 82,124 KB
実行使用メモリ 76,616 KB
最終ジャッジ日時 2024-12-17 18:41:16
合計ジャッジ時間 5,106 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

'''
これ、 https://hayato.io/2014/pirates/ のまんまでは?
'''

#!/usr/bin/env python3

import sys


def solve():
    num_pirates, coin = list(map(int, input().split()))

    def solve(proposal):
        necessary_vote = (len(proposal) + 1) // 2
        ranks = sorted((n, i) for i, n in enumerate(proposal))
        necessary_coin = sum(n + 1 for n, _ in ranks[:necessary_vote])
        if coin >= necessary_coin:
            return [(n + 1 if ranks.index((n, i)) < necessary_vote else 0)
                    for i, n in enumerate(proposal)] + [coin - necessary_coin]
        return proposal + [-1]

    def pretty(x):
        if x == -1:
            return 'x'
        if x > 9:
            return 'G'
        return str(x)

    optimal_proposal = []

    for member in range(num_pirates):
        optimal_proposal = solve(optimal_proposal)

    optimal_proposal = optimal_proposal[::-1]
    print(*optimal_proposal)


if __name__ == '__main__':
    solve()
0