結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2021-08-13 11:37:39 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 115 ms / 5,000 ms |
| コード長 | 1,171 bytes |
| コンパイル時間 | 188 ms |
| コンパイル使用メモリ | 32,000 KB |
| 実行使用メモリ | 93,824 KB |
| 最終ジャッジ日時 | 2024-12-14 15:48:15 |
| 合計ジャッジ時間 | 1,099 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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 'mypr':
main.c:8:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration]
8 | #define pc(c) putchar_unlocked(c)
| ^~~~~~~~~~~~~~~~
main.c:23:9: note: in expansion of macro 'pc'
23 | pc((dp[i][j][1] & 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][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