結果
問題 | No.1635 Let’s Sort Integers!! |
ユーザー | Shirotsume |
提出日時 | 2022-07-29 18:11:13 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,660 bytes |
コンパイル時間 | 157 ms |
コンパイル使用メモリ | 82,044 KB |
実行使用メモリ | 223,476 KB |
最終ジャッジ日時 | 2024-07-19 09:04:16 |
合計ジャッジ時間 | 18,884 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
53,888 KB |
testcase_01 | AC | 41 ms
54,272 KB |
testcase_02 | AC | 40 ms
54,400 KB |
testcase_03 | AC | 39 ms
54,400 KB |
testcase_04 | AC | 39 ms
54,016 KB |
testcase_05 | AC | 42 ms
54,272 KB |
testcase_06 | AC | 43 ms
54,528 KB |
testcase_07 | AC | 40 ms
54,656 KB |
testcase_08 | AC | 43 ms
54,144 KB |
testcase_09 | AC | 40 ms
54,272 KB |
testcase_10 | AC | 41 ms
54,656 KB |
testcase_11 | AC | 42 ms
53,888 KB |
testcase_12 | AC | 41 ms
54,528 KB |
testcase_13 | AC | 42 ms
54,656 KB |
testcase_14 | AC | 43 ms
54,400 KB |
testcase_15 | AC | 41 ms
54,016 KB |
testcase_16 | AC | 41 ms
54,528 KB |
testcase_17 | AC | 42 ms
54,528 KB |
testcase_18 | AC | 42 ms
54,272 KB |
testcase_19 | AC | 42 ms
53,888 KB |
testcase_20 | AC | 42 ms
53,760 KB |
testcase_21 | AC | 41 ms
54,144 KB |
testcase_22 | AC | 40 ms
54,272 KB |
testcase_23 | AC | 41 ms
54,144 KB |
testcase_24 | AC | 41 ms
54,400 KB |
testcase_25 | AC | 42 ms
54,016 KB |
testcase_26 | AC | 41 ms
53,888 KB |
testcase_27 | AC | 41 ms
54,144 KB |
testcase_28 | AC | 41 ms
54,144 KB |
testcase_29 | AC | 41 ms
53,888 KB |
testcase_30 | AC | 40 ms
54,144 KB |
testcase_31 | AC | 43 ms
53,888 KB |
testcase_32 | AC | 42 ms
54,400 KB |
testcase_33 | AC | 41 ms
54,384 KB |
testcase_34 | AC | 43 ms
54,272 KB |
testcase_35 | AC | 41 ms
53,888 KB |
testcase_36 | AC | 41 ms
54,272 KB |
testcase_37 | AC | 41 ms
54,656 KB |
testcase_38 | AC | 42 ms
54,272 KB |
testcase_39 | AC | 42 ms
54,272 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 | 41 ms
53,888 KB |
testcase_48 | AC | 42 ms
53,888 KB |
testcase_49 | AC | 43 ms
54,912 KB |
testcase_50 | AC | 45 ms
55,040 KB |
testcase_51 | AC | 48 ms
60,800 KB |
testcase_52 | AC | 44 ms
55,168 KB |
testcase_53 | AC | 43 ms
54,784 KB |
testcase_54 | AC | 44 ms
54,784 KB |
testcase_55 | AC | 45 ms
55,260 KB |
testcase_56 | AC | 44 ms
54,528 KB |
testcase_57 | AC | 50 ms
60,288 KB |
testcase_58 | AC | 44 ms
54,400 KB |
testcase_59 | AC | 42 ms
53,632 KB |
testcase_60 | AC | 374 ms
223,476 KB |
testcase_61 | AC | 321 ms
193,152 KB |
testcase_62 | AC | 294 ms
186,240 KB |
testcase_63 | AC | 336 ms
207,360 KB |
testcase_64 | AC | 305 ms
183,168 KB |
testcase_65 | AC | 225 ms
169,600 KB |
testcase_66 | AC | 232 ms
169,600 KB |
testcase_67 | AC | 230 ms
169,472 KB |
testcase_68 | AC | 41 ms
54,016 KB |
testcase_69 | AC | 41 ms
53,888 KB |
testcase_70 | AC | 333 ms
223,360 KB |
testcase_71 | AC | 327 ms
202,440 KB |
testcase_72 | AC | 325 ms
199,808 KB |
testcase_73 | AC | 324 ms
206,976 KB |
testcase_74 | AC | 296 ms
185,216 KB |
testcase_75 | RE | - |
testcase_76 | RE | - |
testcase_77 | RE | - |
testcase_78 | AC | 41 ms
54,016 KB |
testcase_79 | AC | 41 ms
54,272 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 - k) 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 - k) 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)