結果
問題 | No.10 +か×か |
ユーザー |
![]() |
提出日時 | 2015-07-17 18:47:20 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 908 bytes |
コンパイル時間 | 731 ms |
コンパイル使用メモリ | 85,712 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-08 08:25:55 |
合計ジャッジ時間 | 2,931 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 3 WA * 1 RE * 8 |
ソースコード
#include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <complex> #include <queue> #include <set> #include <map> 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; vector<int> A; std::string dp[550][55]; std::string dfs(int now, int idx, string const& str) { auto& ret = dp[now][idx]; if(!ret.empty()) { return ret; } ret = "1111111111111111111111111111111111111111111111111111111111111111111111"; if(idx == N) { if(tot != now) { return ret; } return ret = str; } return ret = min(dfs(now+A[idx], idx+1, str + "0"), dfs(now*A[idx], idx+1, str + "1")); } int main() { cin >> N >> tot; rep(i, N) { int a; cin >> a; A.push_back(a); } auto ans = dfs(A[0], 1, ""); rep(i, ans.size()) { cout << (ans[i] == '0' ? '+' : '*'); } cout << endl; return 0; }