結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
k
|
| 提出日時 | 2014-10-30 09:42:05 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,127 bytes |
| コンパイル時間 | 1,057 ms |
| コンパイル使用メモリ | 88,532 KB |
| 実行使用メモリ | 8,448 KB |
| 最終ジャッジ日時 | 2024-12-30 13:58:54 |
| 合計ジャッジ時間 | 13,906 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 9 WA * 1 TLE * 2 |
ソースコード
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <string>
#include <map>
using namespace std;
map <vector <char>, bool> memo;
int total;
vector <int> a;
vector <char> ans;
bool rec(vector <char> p, int val) {
if (memo.find(p) != memo.end()) return memo[p];
if (p.size() == a.size()-1) {
if (val == total) {
ans = p;
return true;
}
return false;
}
if (val >= total) return false;
p.push_back('+');
if (rec(p, val+a[p.size()])) {
p.pop_back();
return memo[p]=true;
}
p.pop_back();
p.push_back('*');
if (rec(p, val*a[p.size()])) {
p.pop_back();
return memo[p]=true;
}
return false;
}
int main() {
int n;
cin >> n;
cin >> total;
for (int i = 0; i < n; i++) {
int x; cin >> x; a.push_back(x);
}
vector <char> p;
rec(p, a[0]);
for (int i = 0; i < ans.size(); i++) cout << ans[i];
cout << endl;
}
k