結果

問題 No.30 たこやき工場
ユーザー bal4ubal4u
提出日時 2019-08-27 09:29:27
言語 C
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 1,233 bytes
コンパイル時間 345 ms
コンパイル使用メモリ 31,744 KB
実行使用メモリ 8,476 KB
最終ジャッジ日時 2024-04-26 15:36:31
合計ジャッジ時間 7,001 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
6,784 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 0 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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:15:24: note: in expansion of macro 'gc'
   15 |         int n = 0, c = gc();
      |                        ^~
main.c: In function 'out':
main.c:8:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration]
    8 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:23:17: note: in expansion of macro 'pc'
   23 |         if (!n) pc('0');
      |                 ^~

ソースコード

diff #

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

#include <stdio.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];
unsigned unit[MAX], ans[MAX];

unsigned dfs(int k) {
	int i;
	if (unit[k] == 0) {
		if (hi[k] == 0) unit[k] = 1;
		else for (i = 0; i < hi[k]; i++) unit[k] += dfs(to[k][i]);
	}
	return unit[k];
}

void req(int k, int q) {
	int i;
	ans[k] += unit[k]*q;
	for (i = 0; i < hi[k]; i++) req(to[k][i], Q[k][i]*q);
}

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

	for (i = N; i >= 1; i--) dfs(i);
	for (i = 0; i < hi[N]; i++) req(to[N][i], Q[N][i]);

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