結果

問題 No.115 遠足のおやつ
ユーザー cympfhcympfh
提出日時 2015-08-22 15:49:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 2,555 bytes
コンパイル時間 1,722 ms
コンパイル使用メモリ 167,412 KB
実行使用メモリ 5,808 KB
最終ジャッジ日時 2023-08-31 00:35:31
合計ジャッジ時間 3,249 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 4 ms
4,424 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,388 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 3 ms
4,384 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,384 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 3 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 3 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 4 ms
4,484 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 3 ms
4,376 KB
testcase_38 AC 6 ms
5,808 KB
testcase_39 AC 7 ms
5,140 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define loop for(;;)
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;
#define inf (1e9)
#define eps (1e-9)
using Integer = long long;
using Real = long double;
const Real PI = acosl(-1);

template<class S, class T> inline
ostream& operator<<(ostream&os, pair<S,T> p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template<class S, class T, class U> inline
ostream& operator<<(ostream&os, tuple<S,T,U> t) {
  return os << '('
    << get<0>(t) << ", "
    << get<1>(t) << ", "
    << get<2>(t) << ')';
}

template<class T> inline
ostream& operator<<(ostream&os, set<T> v) {
  os << "(set";
  for (T item: v) os << ' ' << item;
  os << ")";
  return os;
}

template<class T> inline
ostream& operator<<(ostream&os, vector<T> v) {
  if (v.size() == 0) { return os << "(empty)"; }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

template<class T> inline
istream& operator>>(istream&is, vector<T>&v) {
  rep (i, v.size()) is >> v[i];
  return is;
}

//           ^   >  v   <
int dx[] = { -1, 0, 1,  0 };
int dy[] = {  0, 1, 0, -1 };

using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;

int sum(set<int>&xs) {
  int r = 0;
  for (int x: xs) r += x;
  return r;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout.setf(ios::fixed);
  cout.precision(10);
  random_device dev;
  mt19937 rand(dev());

  int n, d, k; cin >> n >> d >> k;
  vector<vector<bool>> ok(k+1, vector<bool> (d+1, false));
  ok[0][0] = true;
  vector<vector<set<int>>> table(k+1, vector<set<int>> (d+1));
  // table[i][j] = i個買ってj円であるようなセット
  // ok[i][j] = が存在している

  for (int i = 1; i <= k; ++i) {
    for (int j = 1; j <= d; ++j) {
      for (int j2 = max(0, j-n); j2 < j; ++j2) {
        int a = j-j2;
        if (not ok[i-1][j2]) continue;
        if (table[i-1][j2].count(a) == 0) {
          table[i][j] = table[i-1][j2];
          table[i][j].insert(a);
          ok[i][j] = true;
          break;
        }
      }
    }
  }

  rep (i, k+1) {
    rep (j, d+1) {
      if (not ok[i][j]) continue;
      if (sum(table[i][j]) != j) {
        trace(make_pair(i,j));
        trace(table[i][j]);
        return 1;
      }
    }
  }

  if (table[k][d].size() == k) {
    vi ans;
    for (int x: table[k][d])
      ans.push_back(x);
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}
0