結果

問題 No.2027 (1, 2, 3, …, N) 's Subset Sum
ユーザー bluemeganebluemegane
提出日時 2022-08-05 22:33:11
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 901 bytes
コンパイル時間 1,057 ms
コンパイル使用メモリ 67,504 KB
実行使用メモリ 33,356 KB
最終ジャッジ日時 2023-10-13 23:54:47
合計ジャッジ時間 5,554 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
23,608 KB
testcase_01 AC 65 ms
23,692 KB
testcase_02 AC 99 ms
28,412 KB
testcase_03 AC 61 ms
21,580 KB
testcase_04 AC 105 ms
31,140 KB
testcase_05 AC 105 ms
33,356 KB
testcase_06 AC 104 ms
33,268 KB
testcase_07 AC 77 ms
22,664 KB
testcase_08 AC 99 ms
32,356 KB
testcase_09 AC 76 ms
22,600 KB
testcase_10 AC 85 ms
28,160 KB
testcase_11 AC 79 ms
25,160 KB
testcase_12 AC 82 ms
27,576 KB
testcase_13 AC 74 ms
24,332 KB
testcase_14 AC 67 ms
23,700 KB
testcase_15 AC 84 ms
27,832 KB
testcase_16 AC 86 ms
26,260 KB
testcase_17 AC 65 ms
21,564 KB
testcase_18 AC 64 ms
21,500 KB
testcase_19 AC 64 ms
21,608 KB
testcase_20 AC 66 ms
21,672 KB
testcase_21 AC 65 ms
21,492 KB
testcase_22 AC 87 ms
28,224 KB
testcase_23 AC 77 ms
22,616 KB
testcase_24 AC 68 ms
23,560 KB
testcase_25 AC 92 ms
31,280 KB
testcase_26 AC 70 ms
21,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System.Linq;
using System;

public class Hello
{
    static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = long.Parse(line[0]);
        var s = long.Parse(line[1]);
        getAns(n, s);
    }
    static void getAns(long n, long s)
    {
        long w = 0;
        for (long i = 1; i <= n; i++)
        {
            w += i;
            if (w == s)
            {
                Console.WriteLine(i);
                Console.WriteLine(string.Join(" ", Enumerable.Range(1, (int)i)));
                return;
            }
            if (w > s)
            {
                var d = w - s;
                var ans = Enumerable.Range(1, (int)i).ToList();
                ans.Remove((int)d);
                Console.WriteLine(i - 1);
                Console.WriteLine(string.Join(" ", ans));
                return;
            }
        }
    }
}
0