結果
| 問題 |
No.2027 (1, 2, 3, …, N) 's Subset Sum
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-08-29 20:27:39 |
| 言語 | C# (.NET 8.0.404) |
| 結果 |
AC
|
| 実行時間 | 167 ms / 2,000 ms |
| コード長 | 809 bytes |
| コンパイル時間 | 18,896 ms |
| コンパイル使用メモリ | 168,880 KB |
| 実行使用メモリ | 189,168 KB |
| 最終ジャッジ日時 | 2024-11-06 18:03:26 |
| 合計ジャッジ時間 | 12,440 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 25 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (101 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/
ソースコード
using System.Collections.Generic;
using static System.Console;
using static System.Linq.Enumerable;
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]; }
}