結果
問題 | No.10 +か×か |
ユーザー |
![]() |
提出日時 | 2015-05-20 11:17:08 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 19 ms / 5,000 ms |
コード長 | 1,027 bytes |
コンパイル時間 | 1,300 ms |
コンパイル使用メモリ | 159,336 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-14 15:29:46 |
合計ジャッジ時間 | 1,937 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) repi(i,0,n) #define repi(i,a,b) for(int i=int(a);i<int(b);++i) template<class T>bool chmin(T&a,const T&b){return a>b?a=b,1:0;} const int N = 50; const int M = 100100; int n, total, a[N]; void input() { cin >> n >> total; rep(i, n) cin >> a[i]; } const long inf = 1L << 60; long dp[2][M]; void solve() { int cur = 0, suc = 1; fill_n(dp[cur], total + 1, inf); dp[cur][a[0]] = 0; repi(i, 1, n) { fill_n(dp[suc], total + 1, inf); rep(x, total + 1) if (dp[cur][x] != inf) { chmin(dp[suc][x + a[i]], dp[cur][x]); const int nx = x * a[i]; if (nx <= total) { chmin(dp[suc][nx], dp[cur][x] | 1L << (n - i - 1)); } } swap(cur, suc); } for (int i = n - 2; i >= 0; --i) { cout << "+*"[dp[cur][total] >> i & 1]; } cout << endl; } int main() { cin.tie(0); ios_base::sync_with_stdio(false); input(); solve(); }