結果

問題 No.2027 (1, 2, 3, …, N) 's Subset Sum
ユーザー Raysphere24Raysphere24
提出日時 2022-08-29 20:25:12
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 148 ms / 2,000 ms
コード長 737 bytes
コンパイル時間 13,188 ms
コンパイル使用メモリ 168,328 KB
実行使用メモリ 188,676 KB
最終ジャッジ日時 2024-04-24 10:25:21
合計ジャッジ時間 11,957 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
30,592 KB
testcase_01 AC 48 ms
30,592 KB
testcase_02 AC 139 ms
63,224 KB
testcase_03 AC 49 ms
30,720 KB
testcase_04 AC 148 ms
62,976 KB
testcase_05 AC 143 ms
62,848 KB
testcase_06 AC 144 ms
63,104 KB
testcase_07 AC 108 ms
40,192 KB
testcase_08 AC 141 ms
57,344 KB
testcase_09 AC 112 ms
49,152 KB
testcase_10 AC 118 ms
45,440 KB
testcase_11 AC 111 ms
44,288 KB
testcase_12 AC 114 ms
43,648 KB
testcase_13 AC 61 ms
37,376 KB
testcase_14 AC 54 ms
33,376 KB
testcase_15 AC 123 ms
51,064 KB
testcase_16 AC 118 ms
45,952 KB
testcase_17 AC 50 ms
30,976 KB
testcase_18 AC 51 ms
30,720 KB
testcase_19 AC 50 ms
30,848 KB
testcase_20 AC 48 ms
31,232 KB
testcase_21 AC 50 ms
31,104 KB
testcase_22 AC 119 ms
47,360 KB
testcase_23 AC 64 ms
39,800 KB
testcase_24 AC 54 ms
33,152 KB
testcase_25 AC 124 ms
50,304 KB
testcase_26 AC 59 ms
188,676 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (84 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using static System.Console;

var (N, S) = Util.ReadLongs();

List<long> ans = new();
HashSet<long> visited = new();

bool Search(long n, long s)
{
	if (n == 0) return s == 0;
	if (s < 0) return false;

	if (!visited.Add(N * s + n)) return false;

	if (Search(n - 1, s - n)) {
		ans.Add(n);
		return true;
	}

	return Search(n - 1, s);
}

if (Search(N, S)) {
	WriteLine(ans.Count);
	WriteLine(string.Join(' ', ans));
}
else {
	WriteLine("Impossible");
}

static class Util
{
	public static int[] ReadInts() => ReadLine()!.Split().Select(int.Parse).ToArray();
	public static long[] ReadLongs() => ReadLine()!.Split().Select(long.Parse).ToArray();
	public static void Deconstruct<T>(this T[] v, out T a, out T b) { a = v[0]; b = v[1]; }
}
0