結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
moti
|
| 提出日時 | 2015-07-25 01:17:10 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 20 ms / 5,000 ms |
| コード長 | 1,167 bytes |
| コンパイル時間 | 705 ms |
| コンパイル使用メモリ | 81,200 KB |
| 実行使用メモリ | 24,996 KB |
| 最終ジャッジ日時 | 2024-12-14 15:30:38 |
| 合計ジャッジ時間 | 1,465 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
ソースコード
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <set>
#include <map>
#include <assert.h>
#include <cstring>
using namespace std;
#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
int N, tot;
int A[55];//vector<int> A;
int constexpr Max = 100001;
int dp[Max][55];
bool dfs(int now, int idx) {
auto& ope = dp[now][idx];
if(idx == N) { return now == tot; }
if(ope == 2) { return false; }
if(ope >= 0) { return true; }
if(now + A[idx] < Max && dfs(now + A[idx], idx+1)) {
ope = 0; return true;
}
if(now * A[idx] < Max && dfs(now * A[idx], idx+1)) {
ope = 1; return true;
}
ope = 2;
return false;
}
int main() {
memset(dp, -1, sizeof dp);
cin >> N >> tot;
// A.resize(N);
rep(i, N) {
cin >> A[i];
}
assert(dfs(A[0], 1));
std::string ans;
int num = A[0];
REP(i, 1, N) {
if(dp[num][i] == 0) {
ans += '+';
num += A[i];
}
else if(dp[num][i] == 1) {
ans += '*';
num *= A[i];
}
else {
assert(false);
}
}
cout << ans << endl;
return 0;
}
moti