結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-05-03 06:21:10 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 789 bytes |
| コンパイル時間 | 641 ms |
| コンパイル使用メモリ | 71,888 KB |
| 実行使用メモリ | 10,272 KB |
| 最終ジャッジ日時 | 2024-09-14 05:11:14 |
| 合計ジャッジ時間 | 7,126 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 TLE * 1 -- * 7 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
int n;
int t;
std::vector<int> a(50, -1);
std::string s;
bool solve(int r, int i) {
if (r > t) {
return false;
}
if (i == n) {
if (r == t) {
return true;
} else {
return false;
}
}
if (solve(r + a[i], i + 1)) {
s.push_back('+');
return true;
} else if (solve(r * a[i], i + 1)) {
s.push_back('*');
return true;
} else {
return false;
}
}
int main() {
std::cin >> n >> t;
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
int r = a[0];
if(!solve(r, 1)) {
return 1;
}
std::reverse(s.begin(), s.end());
std::cout << s << std::endl;
}