結果

問題 No.625 ソンタクロース
ユーザー yuzupomyuzupom
提出日時 2017-12-28 19:06:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 283 ms / 4,000 ms
コード長 1,301 bytes
コンパイル時間 606 ms
コンパイル使用メモリ 10,800 KB
実行使用メモリ 8,296 KB
最終ジャッジ日時 2023-08-23 08:02:51
合計ジャッジ時間 2,471 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,120 KB
testcase_01 AC 16 ms
8,112 KB
testcase_02 AC 16 ms
8,156 KB
testcase_03 AC 15 ms
8,056 KB
testcase_04 AC 15 ms
8,064 KB
testcase_05 AC 16 ms
8,212 KB
testcase_06 AC 17 ms
8,112 KB
testcase_07 AC 15 ms
8,112 KB
testcase_08 AC 16 ms
8,104 KB
testcase_09 AC 17 ms
8,116 KB
testcase_10 AC 16 ms
8,156 KB
testcase_11 AC 16 ms
8,164 KB
testcase_12 AC 16 ms
8,084 KB
testcase_13 AC 15 ms
8,136 KB
testcase_14 AC 16 ms
8,116 KB
testcase_15 AC 41 ms
8,132 KB
testcase_16 AC 25 ms
8,016 KB
testcase_17 AC 130 ms
8,084 KB
testcase_18 AC 283 ms
8,132 KB
testcase_19 AC 58 ms
8,296 KB
testcase_20 AC 60 ms
8,192 KB
testcase_21 AC 40 ms
8,104 KB
testcase_22 AC 230 ms
8,116 KB
testcase_23 AC 33 ms
8,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M = map(int,input().split())
ANS = [-1 for i in range(N)]
tmp = []
for i in range(N-1, -1, -1):
    if i == N-4:
        ans = [x for x in ANS]
    else:
        ans = [x for x in tmp]
    if i == N-1:
        ANS[i] = M
        continue
    if i == N-2:
        ANS[i] = -1
        continue
    if i == N-3:
        ANS[i] = M
        ANS[i+1] = 0
        ANS[i+2] = 0
        continue
    if N - i > 2*M + 1:
        break
    rest = M
    required = int((N-i)/2)
    satisfied = 0
    over1 = []
    for j in range(N-1, i, -1):       
        if ans[j] < 0:
            satisfied += 1
            ans[j] = 0
        elif ans[j] == 0:
            if satisfied < required:
                ans[j] = 1
                rest -= 1
                satisfied += 1
        elif ans[j] >= 1:
            over1.append((ans[j], -j))
            ans[j] = 0          
    if satisfied < required and len(over1) > 0 and rest > 1:
        over1.sort()
        while satisfied < required and len(over1) > 0:
            p,n = over1.pop(0)
            satisfied += 1
            ans[-n] = p+1
            rest -= p+1
    if rest >= 0 and satisfied >= required:
        ans[i] = rest
        tmp = [x for x in ans]
        ANS = [x for x in ans]
    else:
        tmp = [x for x in ans]
print(' '.join(map(str,ANS)))
0