結果

問題 No.2027 (1, 2, 3, …, N) 's Subset Sum
ユーザー ThetaTheta
提出日時 2022-10-26 14:52:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 416 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 10,504 KB
実行使用メモリ 19,108 KB
最終ジャッジ日時 2023-09-17 07:50:07
合計ジャッジ時間 3,701 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,832 KB
testcase_01 AC 16 ms
7,772 KB
testcase_02 AC 116 ms
17,520 KB
testcase_03 AC 16 ms
7,724 KB
testcase_04 AC 118 ms
19,040 KB
testcase_05 AC 118 ms
19,020 KB
testcase_06 AC 120 ms
19,108 KB
testcase_07 AC 48 ms
11,520 KB
testcase_08 AC 108 ms
17,440 KB
testcase_09 AC 47 ms
11,444 KB
testcase_10 AC 71 ms
13,996 KB
testcase_11 AC 54 ms
12,240 KB
testcase_12 AC 61 ms
12,984 KB
testcase_13 AC 41 ms
10,860 KB
testcase_14 AC 25 ms
9,176 KB
testcase_15 AC 68 ms
13,812 KB
testcase_16 AC 74 ms
14,360 KB
testcase_17 AC 17 ms
7,900 KB
testcase_18 AC 16 ms
7,836 KB
testcase_19 AC 16 ms
7,796 KB
testcase_20 AC 17 ms
8,192 KB
testcase_21 AC 16 ms
7,784 KB
testcase_22 AC 73 ms
14,272 KB
testcase_23 AC 46 ms
11,356 KB
testcase_24 AC 24 ms
9,012 KB
testcase_25 AC 85 ms
15,780 KB
testcase_26 AC 33 ms
9,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    N, S = map(int, input().split())

    partial_sum = 0
    for n in range(1, N+1):
        partial_sum += n
        if partial_sum >= S:
            break
    if partial_sum - S == 0:
        print(n)
        print(*range(1, n+1))
        return

    partial = list(range(1, n+1))
    partial.remove(partial_sum - S)
    print(len(partial))
    print(*partial)


if __name__ == "__main__":
    main()
0