結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2021-08-13 12:14:49 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 55 ms / 5,000 ms |
| コード長 | 886 bytes |
| コンパイル時間 | 183 ms |
| コンパイル使用メモリ | 31,104 KB |
| 実行使用メモリ | 33,536 KB |
| 最終ジャッジ日時 | 2024-12-14 15:48:14 |
| 合計ジャッジ時間 | 854 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
コンパイルメッセージ
main.c: In function 'in':
main.c:7:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
7 | #define gc() getchar_unlocked()
| ^~~~~~~~~~~~~~~~
main.c:11:24: note: in expansion of macro 'gc'
11 | int n = 0, c = gc();
| ^~
main.c: In function 'main':
main.c:8:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration]
8 | #define pc(c) putchar_unlocked(c)
| ^~~~~~~~~~~~~~~~
main.c:37:36: note: in expansion of macro 'pc'
37 | for (i = N-2; i >= 0; --i) pc((dp[N-1][total]>>i) & 1? '*': '+');
| ^~
ソースコード
// 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]; // +or*
void chmin(ll *a, ll b) { if (*a == 0 || *a > b) *a = b; }
int max(int a, int b) { return a >= b? a: b; }
int main()
{
int i, j, ma, A;
int N = in(), total = in();
A = in(), dp[0][A] = 1, ma = A;
for (i = 1; i < N; ++i) {
A = in();
for (j = ma; j >= 0; --j) if (dp[i-1][j]) {
int t;
t = j*A; if (t <= total)
chmin(&dp[i][t], (dp[i-1][j]<<1)|1);
t = j+A; if (t <= total)
chmin(&dp[i][t], dp[i-1][j]<<1);
}
ma = max(ma*A, ma+A); if (ma > total) ma = total;
}
for (i = N-2; i >= 0; --i) pc((dp[N-1][total]>>i) & 1? '*': '+');
pc('\n');
return 0;
}
bal4u