結果
| 問題 | No.10 +か×か |
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2021-08-13 11:37:39 |
| 言語 | C (gcc 15.2.0) |
| 結果 |
AC
|
| 実行時間 | 131 ms / 5,000 ms |
| コード長 | 1,171 bytes |
| 記録 | |
| コンパイル時間 | 174 ms |
| コンパイル使用メモリ | 26,824 KB |
| 実行使用メモリ | 93,440 KB |
| 最終ジャッジ日時 | 2025-12-06 14:58:44 |
| 合計ジャッジ時間 | 1,163 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 13 |
ソースコード
// yukicoder: 10 +か×か
// 2021.8.13
#include <stdio.h>
typedef long long ll;
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
int in() { // 非負整数の入力
int n = 0, c = gc();
do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
return n;
}
ll dp[55][100005][3]; // [0]:exist, [1]:+or*, [2]:prev
void chmin(int *a, int b) { if (*a > b) *a = b; }
int max(int a, int b) { return a >= b? a: b; }
void mypr(int i, int j) {
if (i == 0) return;
mypr(i-1, dp[i][j][2]);
pc((dp[i][j][1] & 1)? '*': '+');
}
int main()
{
int i, j, t, ma, A;
int N = in(), total = in();
A = in();
dp[0][A][0] = 1, ma = A;
for (i = 1; i < N; ++i) {
A = in();
for (j = ma; j >= 0; --j) if (dp[i-1][j][0]) {
t = j*A; if (t <= total && (!dp[i][t][0] ||
dp[i][t][1] > ((dp[i-1][j][1]<<1)|1))) {
dp[i][t][0] = 1, dp[i][t][1] = (dp[i-1][j][1]<<1)|1;
dp[i][t][2] = j;
}
t = j+A; if (t <= total && (!dp[i][t][0] ||
dp[i][t][1] > (dp[i-1][j][1]<<1))) {
dp[i][t][0] = 1, dp[i][t][1] = dp[i-1][j][1]<<1;
dp[i][t][2] = j;
}
}
ma = max(ma*A, ma+A), chmin(&ma, total);
}
mypr(N-1, total);
pc('\n');
return 0;
}
bal4u