結果
問題 | No.1635 Let’s Sort Integers!! |
ユーザー | Shirotsume |
提出日時 | 2022-07-29 18:09:18 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,652 bytes |
コンパイル時間 | 155 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 223,456 KB |
最終ジャッジ日時 | 2024-07-19 09:03:41 |
合計ジャッジ時間 | 17,406 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
54,400 KB |
testcase_01 | AC | 42 ms
54,016 KB |
testcase_02 | AC | 41 ms
54,272 KB |
testcase_03 | AC | 40 ms
54,016 KB |
testcase_04 | AC | 41 ms
54,016 KB |
testcase_05 | AC | 42 ms
54,272 KB |
testcase_06 | AC | 42 ms
54,656 KB |
testcase_07 | AC | 42 ms
54,144 KB |
testcase_08 | AC | 42 ms
54,236 KB |
testcase_09 | AC | 43 ms
54,528 KB |
testcase_10 | AC | 43 ms
54,400 KB |
testcase_11 | AC | 42 ms
54,016 KB |
testcase_12 | AC | 44 ms
54,272 KB |
testcase_13 | AC | 43 ms
54,272 KB |
testcase_14 | AC | 42 ms
54,144 KB |
testcase_15 | AC | 43 ms
54,272 KB |
testcase_16 | AC | 43 ms
54,656 KB |
testcase_17 | AC | 43 ms
54,528 KB |
testcase_18 | AC | 43 ms
54,528 KB |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | AC | 41 ms
54,016 KB |
testcase_28 | AC | 43 ms
54,016 KB |
testcase_29 | AC | 42 ms
54,016 KB |
testcase_30 | AC | 41 ms
54,400 KB |
testcase_31 | AC | 42 ms
54,272 KB |
testcase_32 | AC | 42 ms
54,144 KB |
testcase_33 | AC | 41 ms
54,528 KB |
testcase_34 | AC | 41 ms
54,272 KB |
testcase_35 | AC | 43 ms
54,272 KB |
testcase_36 | AC | 42 ms
54,400 KB |
testcase_37 | AC | 43 ms
54,400 KB |
testcase_38 | AC | 42 ms
54,272 KB |
testcase_39 | AC | 43 ms
54,656 KB |
testcase_40 | RE | - |
testcase_41 | RE | - |
testcase_42 | RE | - |
testcase_43 | RE | - |
testcase_44 | RE | - |
testcase_45 | RE | - |
testcase_46 | RE | - |
testcase_47 | AC | 42 ms
54,272 KB |
testcase_48 | AC | 41 ms
54,016 KB |
testcase_49 | AC | 43 ms
54,912 KB |
testcase_50 | AC | 44 ms
54,528 KB |
testcase_51 | AC | 49 ms
60,544 KB |
testcase_52 | AC | 44 ms
54,912 KB |
testcase_53 | AC | 43 ms
54,912 KB |
testcase_54 | RE | - |
testcase_55 | RE | - |
testcase_56 | RE | - |
testcase_57 | RE | - |
testcase_58 | RE | - |
testcase_59 | AC | 42 ms
54,400 KB |
testcase_60 | AC | 335 ms
223,456 KB |
testcase_61 | AC | 314 ms
193,024 KB |
testcase_62 | AC | 282 ms
186,240 KB |
testcase_63 | AC | 345 ms
207,104 KB |
testcase_64 | AC | 296 ms
183,040 KB |
testcase_65 | RE | - |
testcase_66 | RE | - |
testcase_67 | RE | - |
testcase_68 | AC | 42 ms
54,016 KB |
testcase_69 | AC | 41 ms
54,400 KB |
testcase_70 | AC | 336 ms
223,232 KB |
testcase_71 | AC | 324 ms
202,496 KB |
testcase_72 | AC | 318 ms
199,992 KB |
testcase_73 | AC | 338 ms
207,132 KB |
testcase_74 | AC | 303 ms
185,344 KB |
testcase_75 | RE | - |
testcase_76 | RE | - |
testcase_77 | RE | - |
testcase_78 | AC | 42 ms
54,400 KB |
testcase_79 | AC | 43 ms
54,016 KB |
ソースコード
import sys input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) from collections import deque n, k = mi() if n % 2: if n - 1 <= k <= (n * n - 3) // 2: pass else: exit(print(-1)) if k <= n * (n - 1) // 2: q = deque(range(1, n + 1)) ans = [] ans.append(q.popleft()) p = [] f = 0 for i in range(1, n): if i % 2: now = q.pop() if f + abs(ans[-1] - now) <= k: f += abs(ans[-1] - now) ans.append(now) else: p.append(now) else: now = q.popleft() if f + abs(ans[-1] - now) <= k: f += abs(ans[-1] - now) ans.append(now) else: p.append(now) ans = [ans[0]] + list(sorted(p)) + ans[1:] else: x = (n - 1) // 2 + 2 y = 1 ans = [] for i in range(n): if i % 2: ans.append(y) y += 1 else: ans.append(x) x += 1 now1 = ans.index((n - 1) // 2 + 2) now2 = ans.index((n - 1) // 2 + 2 + (n * n - 3) // 2 - 1) ans[now1], ans[now2] = ans[now2], ans[now1] else: if n - 1 <= k <= (n * n) // 2 - 1: pass else: exit(print(-1)) if k <= n * (n - 1) // 2: q = deque(range(1, n + 1)) ans = [] ans.append(q.popleft()) p = [] f = 0 for i in range(1, n): if i % 2: now = q.pop() if f + abs(ans[-1] - now) <= k: f += abs(ans[-1] - now) ans.append(now) else: p.append(now) else: now = q.popleft() if f + abs(ans[-1] - now) <= k: f += abs(ans[-1] - now) ans.append(now) else: p.append(now) ans = [ans[0]] + list(sorted(p)) + ans[1:] else: x = n // 2 + 1 y = 1 ans = [] for i in range(n): if i % 2: ans.append(y) y += 1 else: ans.append(x) x += 1 now1 = ans.index(n // 2 + 1) now2 = ans.index(n // 2 + 1 + (n * n) // 2 - 1) ans[now1], ans[now2] = ans[now2], ans[now1] cnt = 0 for i in range(n - 1): cnt += abs(ans[i] - ans[i + 1]) assert cnt == k print(*ans)