結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-01-19 14:25:39 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 777 bytes |
| コンパイル時間 | 462 ms |
| コンパイル使用メモリ | 64,000 KB |
| 実行使用メモリ | 13,888 KB |
| 最終ジャッジ日時 | 2024-06-22 19:06:55 |
| 合計ジャッジ時間 | 6,970 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 TLE * 1 -- * 7 |
ソースコード
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
int n, total;
vector<int> a;
string ans;
bool calc(int result, int idx) {
if (idx == n) {
// cout << ans << " " << result << endl;
if (result == total) {
return true;
}
return false;
}
for (int i = 0; i < 2; i++) {
int next;
if (i == 0) {
ans[idx - 1] = '+';
next = result + a[idx];
} else {
ans[idx - 1] = '*';
next = result * a[idx];
}
if (next <= total) {
if (calc(next, idx + 1)) {
return true;
}
}
}
return false;
}
int main() {
cin >> n;
cin >> total;
a.assign(n, 0);
ans.assign(n - 1, '?');
for (int i = 0; i < n; i++) {
cin >> a[i];
}
calc(a[0], 1);
cout << ans << endl;
return 0;
}