結果
問題 | No.1701 half price |
ユーザー | bluemegane |
提出日時 | 2021-10-09 07:46:15 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 1,168 ms / 3,000 ms |
コード長 | 1,720 bytes |
コンパイル時間 | 2,037 ms |
コンパイル使用メモリ | 70,024 KB |
実行使用メモリ | 221,340 KB |
最終ジャッジ日時 | 2023-10-01 01:16:56 |
合計ジャッジ時間 | 6,012 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 67 ms
24,408 KB |
testcase_01 | AC | 67 ms
22,392 KB |
testcase_02 | AC | 67 ms
22,408 KB |
testcase_03 | AC | 66 ms
22,352 KB |
testcase_04 | AC | 66 ms
24,560 KB |
testcase_05 | AC | 67 ms
22,360 KB |
testcase_06 | AC | 68 ms
24,476 KB |
testcase_07 | AC | 71 ms
24,492 KB |
testcase_08 | AC | 63 ms
22,516 KB |
testcase_09 | AC | 63 ms
22,428 KB |
testcase_10 | AC | 63 ms
22,284 KB |
testcase_11 | AC | 68 ms
22,428 KB |
testcase_12 | AC | 68 ms
22,504 KB |
testcase_13 | AC | 68 ms
22,468 KB |
testcase_14 | AC | 67 ms
22,468 KB |
testcase_15 | AC | 64 ms
20,212 KB |
testcase_16 | AC | 66 ms
26,396 KB |
testcase_17 | AC | 83 ms
22,828 KB |
testcase_18 | AC | 64 ms
20,852 KB |
testcase_19 | AC | 64 ms
22,812 KB |
testcase_20 | AC | 64 ms
22,368 KB |
testcase_21 | AC | 1,168 ms
221,340 KB |
ソースコード
using System.Collections.Generic; using System.Linq; using static System.Math; using System; public class P { public long sum { get; set; } public string x { get; set; } } public class Hello { static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var w = long.Parse(line[1]); line = Console.ReadLine().Trim().Split(' '); var a = Array.ConvertAll(line, long.Parse); getAns(n, w, a); } static string change(string t) { var res = ""; foreach (var x in t) { if (x == '2') res += "1"; else res += x; } return res; } static long w0(int n, long[] a) { var c = a.Count(x => x == 0); return (long)Pow(2, c) - 1L; } static void getAns(int n, long w, long[] a) { if (w == 0) { Console.WriteLine(w0(n, a)); return; } var hs = new HashSet<string>(); var q = new Queue<P>(); q.Enqueue(new P { x = "2", sum = a[0] }); q.Enqueue(new P { x = "1", sum = a[0] / 2L }); q.Enqueue(new P { x = "0", sum = 0 }); while (q.Count() > 0) { var t = q.Dequeue(); var tn = t.x.Length; if (tn == n) { if (t.sum == w) hs.Add(change(t.x)); continue; } if (t.sum + a[tn] <= w) q.Enqueue(new P { x = t.x + "2", sum = t.sum + a[tn] }); if (t.sum + a[tn] / 2L <= w) q.Enqueue(new P { x = t.x + "1", sum = t.sum + a[tn] / 2L }); q.Enqueue(new P { x = t.x + "0", sum = t.sum }); } Console.WriteLine(hs.Count()); } }