結果

問題 No.115 遠足のおやつ
ユーザー siman
提出日時 2021-09-01 02:03:55
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 30 ms / 5,000 ms
コード長 1,017 bytes
コンパイル時間 6,932 ms
コンパイル使用メモリ 139,424 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-26 14:47:25
合計ジャッジ時間 5,134 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

int N, D, K;
bool visited[101][1010][11];
bool g_found;

void dfs(int i, int d, int k, vector<int> &path) {
  if (g_found) return;
  if (i > N) return;
  if (visited[i][d][k]) return;
  visited[i][d][k] = true;

  if (k == K) {
    if (d == D) {
      for (int j = 0; j < k; ++j) {
        cout << path[j];
        if (j + 1 < k) cout << " ";
      }
      cout << endl;

      g_found = true;
      return;
    } else {
      return;
    }
  }

  for (int v = i + 1; v <= N; ++v) {
    path.push_back(v);
    dfs(v, d + v, k + 1, path);
    path.pop_back();
  }
}

int main() {
  cin >> N >> D >> K;
  memset(visited, false, sizeof(visited));
  g_found = false;

  vector<int> path;
  dfs(0, 0, 0, path);

  if (not g_found) {
    cout << -1 << endl;
  }

  return 0;
}
0