結果

問題 No.1701 half price
ユーザー kokatsu
提出日時 2021-10-08 22:21:38
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 16 ms / 3,000 ms
コード長 753 bytes
コンパイル時間 1,857 ms
コンパイル使用メモリ 211,656 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-22 12:44:38
合計ジャッジ時間 2,560 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main() {
    long N, W;
    readf("%d %d\n", N, W);

    auto a = readln.chomp.split.to!(long[]);

    void dfs(long num, long cnt, long bit, ref bool flag) {
        if (cnt == N) {
            if (num == W) {
                flag = true;
            }
        }
        else {
            if (bit & 1) {
                dfs(num+a[cnt], cnt+1, bit>>1, flag);
                dfs(num+a[cnt]/2, cnt+1, bit>>1, flag);
            }
            else {
                dfs(num, cnt+1, bit>>1, flag);
            }
        }
    }

    long res;
    foreach (i; 1 .. 1<<N) {
        long b = i;
        bool canChoose;
        dfs(0, 0, b, canChoose);
        
        if (canChoose) {
            ++res;
        }
    }

    res.writeln;
}
0