結果

問題 No.10 +か×か
ユーザー bal4ubal4u
提出日時 2019-07-24 21:20:52
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,291 bytes
コンパイル時間 1,103 ms
コンパイル使用メモリ 29,488 KB
実行使用メモリ 48,836 KB
最終ジャッジ日時 2023-09-10 20:18:47
合計ジャッジ時間 1,416 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 49 ms
48,836 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 49 ms
48,808 KB
testcase_07 AC 13 ms
17,396 KB
testcase_08 AC 6 ms
7,708 KB
testcase_09 AC 7 ms
9,776 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:9:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    9 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:17:24: 備考: in expansion of macro ‘gc’
   17 |         int n = 0, c = gc();
      |                        ^~
main.c: 関数 ‘main’ 内:
main.c:10:15: 警告: 関数 ‘putchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   10 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:38:39: 備考: in expansion of macro ‘pc’
   38 |         if (s == total) { while (N--) pc('+'); pc('\n'); return 0; }
      |                                       ^~

ソースコード

diff #

// 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, t = 1;
	for (i = 0; i <= N; i++) {
		a[i] = in();
		s += a[i];
		if (t <= total) t *= a[i];
	}
	if (s == total) { while (N--) pc('+'); pc('\n'); return 0; }
	if (t == 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;
}
0