結果

問題 No.30 たこやき工場
ユーザー bal4ubal4u
提出日時 2019-08-28 21:21:29
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,595 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 30,224 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-23 05:21:24
合計ジャッジ時間 999 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,500 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 0 ms
4,376 KB
testcase_05 AC 0 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 0 ms
4,376 KB
testcase_14 AC 0 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 0 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:8:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    8 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:16:24: 備考: in expansion of macro ‘gc’
   16 |         int n = 0, c = gc();
      |                        ^~
main.c: 関数 ‘out’ 内:
main.c:9:15: 警告: 関数 ‘putchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    9 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:24:17: 備考: in expansion of macro ‘pc’
   24 |         if (!n) pc('0');
      |                 ^~

ソースコード

diff #

// yukicoder: 30 たこやき工場
// 2019.8.28 bal4u

#include <stdio.h>
#include <stdlib.h>

#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;
}

void out(unsigned n) {   // 非負整数の表示(出力)
	int i; char b[30];

	if (!n) pc('0');
	else {
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
}

#define MAX 103
int N;
int hi[MAX], to[MAX][MAX], Q[MAX][MAX], a[MAX];
unsigned unit[MAX], ans[MAX];

// トポロジーソート 独立したモジュール
int tans[MAX]; int tsz;   // トポロジーソートの結果。後ろのほうが指されたもの。
void topoSort(int V) {
	int i, j, k;
	static int q[MAX], top, end;
	static int count[MAX];

	for (i = 1; i <= V; i++) for (j = 0; j < hi[i]; j++) count[to[i][j]]++;
	top = end = 0;
	for (i = 1; i <= V; i++) if (!count[i]) q[end++] = i;
	tsz = 0;  while (top < end) {
		tans[tsz++] = i = q[top++];
		for (j = 0; j < hi[i]; j++) {
			k = to[i][j];
			if (--count[k] == 0) q[end++] = k;
		}
	}
}

int main()
{
	int i, M;
	
	N = in(), M = in();
	while (M--) {
		int k, p = in(), q = in(), r = in();
		k = hi[r]++, to[r][k] = p, Q[r][k] = q;
	}
	
	ans[N] = 1;
	topoSort(N);
	for (i = 0; i < tsz; i++) {
		int j, k = tans[i];
		for (j = 0; j < hi[k]; j++) ans[to[k][j]] += ans[k]*Q[k][j];
	}

	for (i = 1; i < N; i++) {
		if (hi[i]) pc('0');
		else out(ans[i]);
		pc('\n');
	}
	return 0;
}
0