結果
| 問題 | No.10 +か×か |
| コンテスト | |
| ユーザー |
kyuna
|
| 提出日時 | 2020-05-02 01:00:41 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 14 ms / 5,000 ms |
| コード長 | 702 bytes |
| 記録 | |
| コンパイル時間 | 740 ms |
| コンパイル使用メモリ | 77,236 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-12-06 14:55:16 |
| 合計ジャッジ時間 | 1,422 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 13 |
ソースコード
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n; cin >> n;
int total; cin >> total;
vector<int> a(n);
for (auto &ai: a) cin >> ai;
string ans;
vector<vector<bool>> dp(n, vector<bool>(total + 1));
auto dfs = [&](auto dfs, int i, int res) {
if (res > total) return ;
if (i == n) {
if (res == total) cout << ans << endl, exit(0);
return ;
}
if (dp[i][res]) return ;
dp[i][res] = true;
ans += '+', dfs(dfs, i + 1, res + a[i]), ans.pop_back();
ans += '*', dfs(dfs, i + 1, res * a[i]), ans.pop_back();
};
dfs(dfs, 1, a[0]);
return 0;
}
kyuna