結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-07-24 21:25:10 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 56 ms / 5,000 ms |
| コード長 | 1,184 bytes |
| コンパイル時間 | 1,293 ms |
| コンパイル使用メモリ | 30,336 KB |
| 実行使用メモリ | 48,256 KB |
| 最終ジャッジ日時 | 2024-12-14 15:42:08 |
| 合計ジャッジ時間 | 906 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
コンパイルメッセージ
main.c: In function 'in':
main.c:9:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
9 | #define gc() getchar_unlocked()
| ^~~~~~~~~~~~~~~~
main.c:17:24: note: in expansion of macro 'gc'
17 | int n = 0, c = gc();
| ^~
main.c: In function 'main':
main.c:10:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration]
10 | #define pc(c) putchar_unlocked(c)
| ^~~~~~~~~~~~~~~~
main.c:34:39: note: in expansion of macro 'pc'
34 | if (s == total) { while (N--) pc('+'); pc('\n'); return 0; }
| ^~
ソースコード
// yukicoder: No.10 +か×か
// 2019.7.24 bal4u
#include <stdio.h>
typedef long long ll;
#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in() { // 非負整数の入力
int n = 0, c = gc();
do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
return n;
}
typedef struct { char i; int s; ll b; } Q;
Q q[10000003]; int top, end;
int total;
int a[53], N;
char vis[100003][53];
int main()
{
int i, s, t; ll b;
N = in()-1, total = in(), s = 0;
for (i = 0; i <= N; i++) a[i] = in(), s += a[i];
if (s == total) { while (N--) pc('+'); pc('\n'); return 0; }
q[0].i = 1, q[0].s = a[0], end = 1;
while (top != end) {
i = q[top].i, s = q[top].s, b = q[top++].b;
if ((t = s + a[i]) <= total && !vis[t][i]) {
vis[t][i] = 1;
if (i == N) { if (t == total) break; }
else q[end].i = i+1, q[end].s = t, q[end++].b = b;
}
if ((t = s * a[i]) > total || vis[t][i]) continue;
vis[t][i] = 1, b |= (1LL << i);
if (i == N) { if (t == total) break; }
else q[end].i = i+1, q[end].s = t, q[end++].b = b;
}
while (N--) b >>= 1, pc(b & 1? '*': '+');
pc('\n');
return 0;
}
bal4u