結果

問題 No.115 遠足のおやつ
ユーザー くれちー
提出日時 2017-02-22 17:16:11
言語 C90
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 873 bytes
コンパイル時間 451 ms
コンパイル使用メモリ 22,528 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2024-12-30 18:55:49
合計ジャッジ時間 36,513 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35 TLE * 5
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:33:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   33 |     scanf("%d %d %d", &n, &d, &k);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#define rep(i, n) for (i = 0; i < n; i++)
#define rrep(i, n) for (i = n; i >= 0; i--)
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
typedef long long ll;

int n, d, k;
bool buy[101];

bool bfs(int idx, int sum, int cnt) {
    if (sum == d && cnt == k) return true;
    if (sum > d) return false;
    if (cnt > k) return false;
    if (idx > n) return false;

    if (bfs(idx + 1, sum + idx, cnt + 1)) {
        buy[idx] = true;
        return true;
    }
    if (bfs(idx + 1, sum, cnt)) {
        buy[idx] = false;
        return true;
    }
    return false;
}

int main() {
    scanf("%d %d %d", &n, &d, &k);

    int i;
    if (bfs(1, 0, 0)) {
        rep(i, n + 1) { if (buy[i + 1]) printf("%d ", i + 1); }
    }
    else puts("-1");
    return 0;
}
0