結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
codershifth
|
| 提出日時 | 2015-07-12 18:17:27 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,703 bytes |
| コンパイル時間 | 1,652 ms |
| コンパイル使用メモリ | 171,636 KB |
| 実行使用メモリ | 10,140 KB |
| 最終ジャッジ日時 | 2024-07-08 05:55:52 |
| 合計ジャッジ時間 | 7,792 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 TLE * 1 -- * 8 |
ソースコード
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,a,b) for(int (i)=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RANGE(vec) (vec).begin(),(vec).end()
using namespace std;
class AddOrMul {
public:
void solve(void) {
int N, Total;
cin>>N>>Total;
vector<int> A(N);
REP(i, N)
cin>>A[i];
vector<string> ans;
// 全探索 + 枝刈り
function<void(int sum, int i, const string &str)> dfs = [&](int sum, int i, const string &str) {
if (i == N)
{
if (sum == Total)
ans.push_back(str);
return;
}
if (sum+A[i] <= Total)
dfs(sum+A[i], i+1, str+"+");
if (sum*A[i] <= Total)
dfs(sum*A[i], i+1, str+"*");
return;
};
dfs(A[0], 1, "");
// 通常の辞書式順序とは違うので自前でやる
sort(RANGE(ans), [](const string &a, const string &b){
REP(i, a.length())
{
if (a[i] == b[i])
continue;
if (a[i] == '+')
return true;
return false;
}
return false;
});
cout<<ans[0]<<endl;
}
};
#if 1
int main(int argc, char *argv[])
{
ios::sync_with_stdio(false);
auto obj = new AddOrMul();
obj->solve();
delete obj;
return 0;
}
#endif
codershifth