結果
問題 | No.10 +か×か |
ユーザー |
|
提出日時 | 2017-01-08 14:10:11 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4,336 ms / 5,000 ms |
コード長 | 2,080 bytes |
コンパイル時間 | 856 ms |
コンパイル使用メモリ | 90,172 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-14 15:38:17 |
合計ジャッジ時間 | 5,886 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 |
ソースコード
#include <iostream>#include <vector>#include <algorithm>#include <array>#include <set>#include <map>#include <queue>#include <tuple>#include <unordered_set>#include <unordered_map>#include <functional>#include <cassert>#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))#define repeat_from(i,m,n) for (int i = (m); (i) < int(n); ++(i))#define repeat_reverse(i,n) for (int i = (n)-1; (i) >= 0; --(i))#define repeat_from_reverse(i,m,n) for (int i = (n)-1; (i) >= int(m); --(i))#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)#define debug(x) #x << " = " << (x) << " "using namespace std;template <class T> void setmax(T & a, T const & b) { if (a < b) a = b; }template <class T> void setmin(T & a, T const & b) { if (b < a) a = b; }template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }int main() {int n, total; cin >> n >> total;vector<int> a(n); repeat (i,n) cin >> a[i];function<int (int, int)> upper_bound = [&](int i, int acc) { return i == n or acc == total+1 ? acc : upper_bound(i+1, min(total+1, max(acc + a[i],acc * a[i]))); };function<int (int, int)> lower_bound = [&](int i, int acc) { return i == n or acc == total+1 ? acc : lower_bound(i+1, min(total+1, min(acc + a[i],acc * a[i]))); };string result;function<bool (int, int)> go = [&](int i, int acc) {if (i == n) return acc == total;int r = upper_bound(i, acc);int l = lower_bound(i, acc);if (l <= total and total <= r) {result.push_back('+');if (go(i+1, acc + a[i])) return true;result.pop_back();result.push_back('*');if (go(i+1, acc * a[i])) return true;result.pop_back();}return false;};go(1, a[0]);cout << result << endl;return 0;}