結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
yuusti
|
| 提出日時 | 2014-12-05 03:16:22 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 727 ms / 5,000 ms |
| コード長 | 1,682 bytes |
| コンパイル時間 | 751 ms |
| コンパイル使用メモリ | 91,436 KB |
| 実行使用メモリ | 335,500 KB |
| 最終ジャッジ日時 | 2024-12-14 15:26:00 |
| 合計ジャッジ時間 | 4,944 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <climits>
#include <bitset>
#include <cassert>
#include <random>
#ifdef _MSC_VER
#include <agents.h>
#endif
#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define UNIQUE(v) (v).erase(unique(ALL(v)), (v).end())
#define MP make_pair
#define MT make_tuple
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1e5 + 10;
int dp[55][N];
string history[55][N];
int a[55];
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n, total;
cin >> n >> total;
rep(i, n) cin >> a[i];
rep(i, 55) rep(j, N) history[i][j] = string(1, '3');
dp[1][a[0]] = 1;
history[1][a[0]] = "";
FOR(i, 1, n){
rep(j, total+1){
if (!dp[i][j]) continue;
if (j * a[i] <= total){
dp[i + 1][j * a[i]] = 1;
history[i + 1][j*a[i]] = min(history[i + 1][j*a[i]], history[i][j] + '2');
}
}
rep(j, total+1){
if (!dp[i][j]) continue;
if (j + a[i] <= total){
dp[i + 1][j + a[i]] = 1;
history[i + 1][j+a[i]] = min(history[i + 1][j+a[i]], history[i][j] + '1');
}
}
}
char c[256] = {};
c['1'] = '+', c['2'] = '*';
for (auto ch : history[n][total]){
cout << c[ch];
}
cout << endl;
return 0;
}
yuusti