結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
srup٩(๑`н´๑)۶
|
| 提出日時 | 2016-11-07 22:12:52 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,558 bytes |
| コンパイル時間 | 1,184 ms |
| コンパイル使用メモリ | 162,076 KB |
| 実行使用メモリ | 8,988 KB |
| 最終ジャッジ日時 | 2024-11-25 04:30:48 |
| 合計ジャッジ時間 | 1,802 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 7 WA * 5 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
//dp[i][j] := i 番目まで見て、+の数が j 個
bool dp[55][100010];
int n, total, a[55];
int main(void){
cin >> n >> total;
rep(i, n) cin >> a[i];
rep(i, 55)rep(j, 100010)dp[i][j] = false;
dp[0][a[0]] = true;
for (int i = 0; i < n - 1; ++i){
for (int j = 0; j <= 100000; ++j){
if(dp[i][j]){
if(j + a[i + 1] <= 100000){
dp[i + 1][j + a[i + 1]] = true;
// printf("1 %d %d\n", i + 1, j + a[i + 1]);
}
if(j * a[i + 1] <= 100000){
dp[i + 1][j * a[i + 1]] = true;
// printf("2 %d %d\n", i + 1, j * a[i + 1]);
}
}
}
}
vector<int> ans;
int now = total;
for (int i = n - 2; i >= 0; --i){
// printf("i %d now %d now-a[i %d\n", i, now, now - a[i]);
if(dp[i][now - a[i + 1]]){
ans.push_back(0);
now -= a[i + 1];
}else{
ans.push_back(1);
now /= a[i + 1];
}
}
reverse(ans.begin(), ans.end());
rep(i, ans.size()){
if(ans[i] == 0){
printf("+");
}else{
printf("*");
}
}
printf("\n");
return 0;
}
srup٩(๑`н´๑)۶