結果
| 問題 |
No.115 遠足のおやつ
|
| コンテスト | |
| ユーザー |
data9824
|
| 提出日時 | 2015-05-08 23:36:21 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,149 bytes |
| コンパイル時間 | 404 ms |
| コンパイル使用メモリ | 62,140 KB |
| 実行使用メモリ | 10,624 KB |
| 最終ジャッジ日時 | 2024-07-05 20:42:03 |
| 合計ジャッジ時間 | 7,172 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 WA * 2 TLE * 1 -- * 24 |
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n;
bool availables[101];
int picked[10];
bool solve(int d, int k) {
if (k == 0) {
return (d == 0); // only if total price equals 0 yen
}
int maxPricePickingUpK = 0;
int pickedCount = 0;
for (int i = n; i >= 1 && pickedCount < k; --i) {
if (availables[i]) {
maxPricePickingUpK += i;
++pickedCount;
}
}
if (d > maxPricePickingUpK) {
return false;
}
bool plausible = false;
for (int i = 1; i <= n; ++i) {
if (availables[i]) {
availables[i] = false;
picked[k - 1] = i;
plausible |= solve(d - i, k - 1);
availables[i] = true;
if (plausible) {
break;
}
}
}
return plausible;
}
int main() {
int d, k;
cin >> n; // sweets
cin >> d; // total yen
cin >> k; // count
fill(&availables[1], &availables[n] + 1, true);
if (n < k) {
cout << -1 << endl;
}
bool solved = solve(d, k);
if (solved) {
vector<int> v(&picked[0], &picked[k - 1] + 1);
for (int i = k - 1; i >= 0; --i) {
if (i != k - 1) {
cout << " ";
}
cout << picked[i];
}
cout << endl;
} else {
cout << -1 << endl;
}
return 0;
}
data9824