結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-12-07 02:18:21 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 48 ms / 5,000 ms |
| コード長 | 732 bytes |
| コンパイル時間 | 257 ms |
| コンパイル使用メモリ | 29,824 KB |
| 最終ジャッジ日時 | 2025-01-05 04:51:55 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:14:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
14 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:16:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
16 | scanf("%d", &a[i]);
| ~~~~~^~~~~~~~~~~~~
ソースコード
#include <cstdio>
#include <cstring>
using int64 = long long;
const int N = 51, S = 1e5 + 10;
int64 dp[N][S];
int a[N];
int main() {
memset(dp, -1, sizeof(dp));
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
auto update = [&](int64 &x, int64 y) {
if (x == -1 || x > y) x = y;
};
dp[0][0] = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= m; ++j) if (dp[i][j] != -1) {
if (j + a[i] <= m) update(dp[i + 1][j + a[i]], dp[i][j]);
if (j * a[i] <= m) update(dp[i + 1][j * a[i]], dp[i][j] | (1ll << (n - i)));
}
}
for (int i = n - 1; i > 0; --i) {
if (dp[n][m] >> i & 1) putchar('*');
else putchar('+');
}
puts("");
return 0;
}