結果
問題 |
No.1635 Let’s Sort Integers!!
|
ユーザー |
|
提出日時 | 2023-12-20 23:22:02 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 907 bytes |
コンパイル時間 | 253 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 196,128 KB |
最終ジャッジ日時 | 2024-09-27 10:15:12 |
合計ジャッジ時間 | 18,182 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 51 WA * 26 |
ソースコード
n, k = map(int, input().split()) if k < n - 1: print(-1) exit() ma = n * (n - 1) // 2 if k > ma: print(-1) exit() K = k P = [] P = [n] l = 2 r = n - 1 k -= n - 1 used = [False] * (n + 1) used[n] = True while k > 0: if len(P) % 2 == 1: d = P[-1] - l if d >= k: used[P[-1] - k] = True P.append(P[-1] - k) k = 0 else: used[l] = True P.append(l) l += 1 k -= d else: d = r - P[-1] if d >= k: used[P[-1] + k] = True P.append(P[-1] + k) k = 0 else: used[r] = True P.append(r) r -= 1 k -= d L = [] for i in range(1, n + 1): if not used[i]: L.append(i) ans = L + P print(*ans) tot = 0 for i in range(n - 1): tot += abs(ans[i] - ans[i + 1]) assert tot == K