結果
| 問題 | 
                            No.1701 half price
                             | 
                    
| コンテスト | |
| ユーザー | 
                             bluemegane
                         | 
                    
| 提出日時 | 2021-10-09 09:17:05 | 
| 言語 | C#(csc)  (csc 3.9.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 1,036 ms / 3,000 ms | 
| コード長 | 1,887 bytes | 
| コンパイル時間 | 2,880 ms | 
| コンパイル使用メモリ | 108,544 KB | 
| 実行使用メモリ | 179,000 KB | 
| 最終ジャッジ日時 | 2024-07-23 21:34:28 | 
| 合計ジャッジ時間 | 5,547 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 20 | 
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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 = new long[n];
        var b = new long[n];
        for (int i = 0; i < n; i++)
        {
            a[i] = long.Parse(line[i]);
            b[i] = a[i] / 2L;
        }
        getAns(n, w, a, b);
    }
    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, long[] b)
    {
        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 = b[0] });
        q.Enqueue(new P { x = "0", sum = 0 });
        while (q.Count() > 0)
        {
            var t = q.Dequeue();
            if (t.sum > w) continue;
            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 + b[tn] <= w) q.Enqueue(new P { x = t.x + "1", sum = t.sum + b[tn] });
            q.Enqueue(new P { x = t.x + "0", sum = t.sum });
        }
        Console.WriteLine(hs.Count());
    }
}
            
            
            
        
            
bluemegane