結果
| 問題 |
No.30 たこやき工場
|
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-08-28 21:21:29 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| コード長 | 1,595 bytes |
| コンパイル時間 | 451 ms |
| コンパイル使用メモリ | 31,360 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-12-21 05:28:55 |
| 合計ジャッジ時間 | 826 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
コンパイルメッセージ
main.c: In function 'in':
main.c:8:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
8 | #define gc() getchar_unlocked()
| ^~~~~~~~~~~~~~~~
main.c:16:24: note: in expansion of macro 'gc'
16 | int n = 0, c = gc();
| ^~
main.c: In function 'out':
main.c:9:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration]
9 | #define pc(c) putchar_unlocked(c)
| ^~~~~~~~~~~~~~~~
main.c:24:17: note: in expansion of macro 'pc'
24 | if (!n) pc('0');
| ^~
ソースコード
// 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;
}
bal4u