結果

問題 No.1635 Let’s Sort Integers!!
ユーザー ShirotsumeShirotsume
提出日時 2022-07-29 18:11:13
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 2,660 bytes
コンパイル時間 911 ms
コンパイル使用メモリ 87,308 KB
実行使用メモリ 243,164 KB
最終ジャッジ日時 2023-09-26 14:54:07
合計ジャッジ時間 27,989 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
71,432 KB
testcase_01 AC 85 ms
71,564 KB
testcase_02 AC 87 ms
71,488 KB
testcase_03 AC 86 ms
71,580 KB
testcase_04 AC 86 ms
71,360 KB
testcase_05 AC 87 ms
71,704 KB
testcase_06 AC 85 ms
71,724 KB
testcase_07 AC 92 ms
71,588 KB
testcase_08 AC 87 ms
71,320 KB
testcase_09 AC 89 ms
71,556 KB
testcase_10 AC 87 ms
71,380 KB
testcase_11 AC 87 ms
71,588 KB
testcase_12 AC 88 ms
71,636 KB
testcase_13 AC 88 ms
71,732 KB
testcase_14 AC 88 ms
71,688 KB
testcase_15 AC 88 ms
71,668 KB
testcase_16 AC 87 ms
71,640 KB
testcase_17 AC 89 ms
71,728 KB
testcase_18 AC 87 ms
71,620 KB
testcase_19 AC 88 ms
71,352 KB
testcase_20 AC 87 ms
71,652 KB
testcase_21 AC 86 ms
71,816 KB
testcase_22 AC 85 ms
71,580 KB
testcase_23 AC 90 ms
71,384 KB
testcase_24 AC 88 ms
71,616 KB
testcase_25 AC 88 ms
71,388 KB
testcase_26 AC 89 ms
71,356 KB
testcase_27 AC 88 ms
71,228 KB
testcase_28 AC 90 ms
71,440 KB
testcase_29 AC 87 ms
71,616 KB
testcase_30 AC 89 ms
71,364 KB
testcase_31 AC 88 ms
71,648 KB
testcase_32 AC 88 ms
71,508 KB
testcase_33 AC 90 ms
71,684 KB
testcase_34 AC 88 ms
71,564 KB
testcase_35 AC 90 ms
71,568 KB
testcase_36 AC 88 ms
71,612 KB
testcase_37 AC 89 ms
71,640 KB
testcase_38 AC 86 ms
71,384 KB
testcase_39 AC 88 ms
71,556 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 89 ms
71,500 KB
testcase_48 AC 85 ms
71,384 KB
testcase_49 AC 91 ms
72,224 KB
testcase_50 AC 93 ms
72,380 KB
testcase_51 AC 96 ms
76,324 KB
testcase_52 AC 91 ms
72,200 KB
testcase_53 AC 88 ms
71,560 KB
testcase_54 AC 91 ms
72,272 KB
testcase_55 AC 92 ms
72,040 KB
testcase_56 AC 93 ms
72,108 KB
testcase_57 AC 93 ms
76,400 KB
testcase_58 AC 91 ms
71,648 KB
testcase_59 AC 85 ms
71,452 KB
testcase_60 AC 404 ms
242,332 KB
testcase_61 AC 372 ms
218,724 KB
testcase_62 AC 335 ms
204,940 KB
testcase_63 AC 374 ms
226,040 KB
testcase_64 AC 358 ms
209,700 KB
testcase_65 AC 265 ms
191,684 KB
testcase_66 AC 257 ms
191,568 KB
testcase_67 AC 258 ms
191,700 KB
testcase_68 AC 86 ms
71,360 KB
testcase_69 AC 86 ms
71,480 KB
testcase_70 AC 370 ms
243,164 KB
testcase_71 AC 366 ms
221,520 KB
testcase_72 AC 364 ms
218,516 KB
testcase_73 AC 376 ms
226,020 KB
testcase_74 AC 359 ms
211,108 KB
testcase_75 RE -
testcase_76 RE -
testcase_77 RE -
testcase_78 AC 87 ms
71,368 KB
testcase_79 AC 87 ms
71,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0