結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-07 22:42:40 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 21 ms / 5,000 ms |
| コード長 | 1,954 bytes |
| コンパイル時間 | 1,963 ms |
| コンパイル使用メモリ | 176,284 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-14 15:45:53 |
| 合計ジャッジ時間 | 2,598 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
ソースコード
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}
const int X = 1e5+1;
//head
int n;
int tot;
int a[50];
bitset<X> dp[51];
bitset<X> *now, *pre;
vi pl[50];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
cin >> tot;
rep(i, n) cin >> a[i];
dp[0].set(0);
now = dp+1;
pre = dp;
rep(i, n) {
rep(j, X) {
if(pre->test(j)) {
if(j+a[i] < X) now->set(j+a[i]);
if(ll(j)*a[i] < X) now->set(j*a[i]);
}
}
pre = now;
now++;
}
pl[n-1].emplace_back(tot);
for(int i = n-2; i >= 0; i--) {
for(int x:pl[i+1]) {
if(x > a[i+1] and dp[i+1].test(x-a[i+1])) pl[i].emplace_back(x-a[i+1]);
if(x%a[i+1] == 0 and dp[i+1].test(x/a[i+1])) pl[i].emplace_back(x/a[i+1]);
}
sort(all(pl[i]));
pl[i].erase(unique(all(pl[i])), pl[i].end());
}
int now = a[0];
rep(i, n-1) {
if(find(all(pl[i+1]), now+a[i+1]) != pl[i+1].end()) {
now += a[i+1];
cout << '+';
} else {
now *= a[i+1];
cout << '*';
}
}
cout << endl;
}