結果
問題 |
No.625 ソンタクロース
|
ユーザー |
|
提出日時 | 2017-12-28 19:06:55 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 345 ms / 4,000 ms |
コード長 | 1,301 bytes |
コンパイル時間 | 224 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-12-21 09:06:19 |
合計ジャッジ時間 | 3,211 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
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)))