結果

問題 No.30 たこやき工場
ユーザー mudbdbmudbdb
提出日時 2015-07-29 20:46:37
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,934 bytes
コンパイル時間 216 ms
コンパイル使用メモリ 26,892 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 05:15:39
合計ジャッジ時間 1,068 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,376 KB
testcase_01 AC 0 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 0 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 0 ms
4,380 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 0 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
int **E;
int **V;
int *I;
long long int **T;
long long int total(int start, int end)
{
  int i;
  if (T[start][end] == -1) {
    if (start == end) {
      T[start][end] = 1;
    } else {
      T[start][end] = 0;
      for (i=0; i<I[end]; i++) {
        T[start][end] += total(start, V[end][i]) * E[V[end][i]][end];
      }
    }
  }
  return T[start][end];
}
int main()
{
  int N;
  int M;
  int *P;
  int *Q;
  int *R;
  scanf("%d", &N);
  scanf("%d", &M);
  P = (int*)malloc(sizeof(int)*M);
  Q = (int*)malloc(sizeof(int)*M);
  R = (int*)malloc(sizeof(int)*M);
  int i;
  for (i=0; i<M; i++) {
    scanf("%d", &(P[i]));
    scanf("%d", &(Q[i]));
    scanf("%d", &(R[i]));
  }

  int no;
  int *R_cnt = (int*)malloc(sizeof(int)*(N+1));
  for (no=0; no<=N; no++) R_cnt[no] = 0;
  for (i=0; i<M; i++) R_cnt[R[i]]++;

  int *P_cnt = (int*)malloc(sizeof(int)*(N+1));
  for (no=0; no<=N; no++) P_cnt[no] = 0;
  for (i=0; i<M; i++) P_cnt[P[i]]++;

  V = (int**)malloc(sizeof(int*)*(N+1));
  V[0] = (int*)malloc(sizeof(int)*(N+1)*N);
  for (i=1; i<=N; i++) V[i] = &(V[i-1][N]);
  I = (int*)malloc(sizeof(int)*(N+1));
  for (i=0; i<=N; i++) I[i] = 0;
  for (i=0; i<M; i++) {
    V[R[i]][I[R[i]]] = P[i];
    I[R[i]]++;
  }

  E = (int**)malloc(sizeof(int*)*(N+1));
  E[0] = (int*)malloc(sizeof(int)*(N+1)*(N+1));
  for (i=0; i<(N+1)*(N+1); i++) E[0][i] = 0;
  for (i=1; i<=N; i++) E[i] = &(E[i-1][N+1]);
  for (i=0; i<M; i++) E[P[i]][R[i]] = Q[i];

  T = (long long int**)malloc(sizeof(long long int*)*(N+1));
  T[0] = (long long int*)malloc(sizeof(long long int)*(N+1)*(N+1));
  for (i=0; i<(N+1)*(N+1); i++) T[0][i] = -1;
  for (i=1; i<=N; i++) T[i] = &(T[i-1][N+1]);

  for (no=1; no<N; no++) {
    if (R_cnt[no] == 0) {
      if (P_cnt[no] == 0) {
        printf("%d\n", 0);
      } else {
        printf("%d\n", total(no, N));
      }
    } else {
      printf("%d\n", 0);
    }
  }
  return 0;
}
0