結果
問題 |
No.10 +か×か
|
ユーザー |
![]() |
提出日時 | 2020-05-03 15:57:28 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 12 ms / 5,000 ms |
コード長 | 943 bytes |
コンパイル時間 | 1,652 ms |
コンパイル使用メモリ | 168,796 KB |
実行使用メモリ | 5,760 KB |
最終ジャッジ日時 | 2024-12-14 15:44:57 |
合計ジャッジ時間 | 2,302 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 |
ソースコード
#include <bits/stdc++.h> using namespace std; int memo[51][100010]; int main() { int N, Total, A[60]; cin >> N >> Total; for (int i = 0; i < N; i++) cin >> A[i]; memo[N - 1][Total] = 1; for (int i = N - 2; i >= 0; i--) { for (int x = 0; x <= Total; x++) { if (memo[i + 1][x]) { if (x - A[i + 1] >= 0) memo[i][x - A[i + 1]] = 1; if (x % A[i + 1] == 0 && !memo[i][x / A[i + 1]]) { memo[i][x / A[i + 1]] = 2; } } } } string ans; int tot = A[0]; for (int i = 0; i < N - 1; i++) { if (memo[i][tot] == 1) { ans.push_back('+'); tot += A[i + 1]; } else if (memo[i][tot] == 2) { ans.push_back('*'); tot *= A[i + 1]; } else { cerr << "error" << endl; } } cout << ans << endl; }