結果

問題 No.2027 (1, 2, 3, …, N) 's Subset Sum
ユーザー lloyzlloyz
提出日時 2022-08-05 21:57:12
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 210 ms / 2,000 ms
コード長 419 bytes
コンパイル時間 465 ms
コンパイル使用メモリ 10,636 KB
実行使用メモリ 19,332 KB
最終ジャッジ日時 2023-10-13 22:43:46
合計ジャッジ時間 4,837 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,840 KB
testcase_01 AC 16 ms
7,752 KB
testcase_02 AC 203 ms
19,240 KB
testcase_03 AC 15 ms
7,832 KB
testcase_04 AC 210 ms
19,224 KB
testcase_05 AC 207 ms
19,144 KB
testcase_06 AC 203 ms
19,332 KB
testcase_07 AC 73 ms
11,528 KB
testcase_08 AC 176 ms
17,660 KB
testcase_09 AC 73 ms
11,608 KB
testcase_10 AC 116 ms
14,164 KB
testcase_11 AC 86 ms
12,284 KB
testcase_12 AC 100 ms
13,132 KB
testcase_13 AC 61 ms
10,976 KB
testcase_14 AC 31 ms
9,296 KB
testcase_15 AC 111 ms
13,952 KB
testcase_16 AC 123 ms
14,472 KB
testcase_17 AC 17 ms
8,280 KB
testcase_18 AC 16 ms
7,760 KB
testcase_19 AC 16 ms
7,772 KB
testcase_20 AC 17 ms
8,192 KB
testcase_21 AC 16 ms
7,824 KB
testcase_22 AC 126 ms
14,368 KB
testcase_23 AC 74 ms
11,624 KB
testcase_24 AC 32 ms
9,072 KB
testcase_25 AC 143 ms
15,672 KB
testcase_26 AC 46 ms
9,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, s = map(int, input().split())

ANS = []
res = 0
for i in range(1, n + 1):
    res += i
    ANS.append(i)
    if i < s - res <= n:
        ANS.append(s - res)
        break
    elif 0 < s - res <= i:
        j = i - (s - res)
        ANS.pop(j)
        ANS.append(s - res + j + 1)
        break
    elif s - res == 0:
        break

#print(ANS)
if sum(ANS) != s:
    print(-1)
    exit()

print(len(ANS))
print(*ANS)
0