結果

問題 No.842 初詣
コンテスト
ユーザー toyama
提出日時 2019-06-28 22:04:57
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 624 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 474 ms
コンパイル使用メモリ 38,240 KB
最終ジャッジ日時 2026-02-22 03:43:00
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// 何どさくさに紛れてJKと付き合ってんすか 許せねぇ
#include <stdio.h>

int k[] = {500, 100, 50, 10, 5, 1};
int c[6];
int g;

int dfs(int pos, int m);

int main()
{
    for (int i = 0; i < 6; i++) {
        scanf("%d", &c[i]);
    }
    scanf("%d", &g);

    if (dfs(0, 0)) {
        puts("YES");
    }
    else {
        puts("NO");
    }

    return 0;
}

int dfs(int pos, int m)
{
    if (m == g) {
        return 1;
    }
    else if (pos >= 6) {
        return 0;
    }

    int res = 0;
    for (int i = 0; i <= c[pos]; i++) {
        res |= dfs(pos + 1, m + k[pos] * i);
    }

    return res;
}
0