結果

問題 No.10 +か×か
ユーザー bal4ubal4u
提出日時 2019-07-24 21:25:10
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 57 ms / 5,000 ms
コード長 1,184 bytes
コンパイル時間 473 ms
コンパイル使用メモリ 29,752 KB
実行使用メモリ 48,820 KB
最終ジャッジ日時 2023-08-21 06:25:50
合計ジャッジ時間 910 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 57 ms
48,812 KB
testcase_04 AC 3 ms
5,152 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 51 ms
48,820 KB
testcase_07 AC 11 ms
17,364 KB
testcase_08 AC 6 ms
7,700 KB
testcase_09 AC 8 ms
9,764 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:34:39: 備考: in expansion of macro ‘pc’
   34 |         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;
	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;
}
0