結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
simezi_tan
|
| 提出日時 | 2015-07-21 18:02:26 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 15 ms / 5,000 ms |
| コード長 | 1,065 bytes |
| コンパイル時間 | 1,281 ms |
| コンパイル使用メモリ | 160,860 KB |
| 実行使用メモリ | 25,344 KB |
| 最終ジャッジ日時 | 2024-12-14 15:30:42 |
| 合計ジャッジ時間 | 1,988 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
ソースコード
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;
const int MX = 110000;
int n, total, a[50], dp[51][MX];
int rec(int c, int s){
if(c == n) return s == total ? 0 : inf;
if(dp[c][s] != -1) return dp[c][s];
if(s + a[c] < MX && rec(c + 1, s + a[c]) < inf) return dp[c][s] = 0;
if(s * a[c] < MX && rec(c + 1, s * a[c]) < inf) return dp[c][s] = 1;
return dp[c][s] = inf;
}
int main(){
cin >> n >> total;
rep(i, n) cin >> a[i];
memset(dp, -1, sizeof(dp));
rec(1, a[0]);
string ans;
int s = a[0];
rep(i, n - 1){
if(dp[i + 1][s] == 0){
ans += "+";
s += a[i + 1];
}
else{
ans += "*";
s *= a[i + 1];
}
}
cout << ans << endl;
return 0;
}
simezi_tan