結果

問題 No.30 たこやき工場
ユーザー ゆるくゆるく
提出日時 2015-02-04 00:49:14
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,179 bytes
コンパイル時間 349 ms
コンパイル使用メモリ 27,152 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 05:14:35
合計ジャッジ時間 1,220 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <math.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>

typedef long long ll;
#define REP(i, x, n) for(i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALLOCA(type, n) ((type*)alloca(sizeof(type) * (n)))
#define MALLOC(type, n) ((type*)malloc(sizeof(type) * (n)))
#define CALLOC(type, n) ((type*)calloc((n), sizeof(type)))
#define REALLOC(type, n, p) ((type*)realloc((p), sizeof(type) * (n)))
#define MAX(a,b) a>b?a:b
#define MIN(a,b) a<b?a:b
typedef struct heap_queue{long *data;long size;}hq;
void heappush(hq *q,int data){long i = q->size;q->size++;while(i > 0){long p = (i - 1) / 2;if (q->data[p]<=data){break;}q->data[i] = q->data[p];i=p;}q->data[i] = data;}
long heappop(hq *q){long ret = q->data[0];q->size--;long data = q->data[q->size];long i = 0;while(i * 2 + 1 < q->size) {long a = i * 2 + 1, b = i * 2 + 2;if (b < q->size && q->data[b] < q->data[a]) {a=b;}if (q->data[a] >= data) {break;}q->data[i] = q->data[a];i=a;}q->data[i]=data;return ret;}

#define SORT(h, n) qsort(h, n, sizeof(h[0]), ASC)
#define RSORT(h, n) qsort(h, n, sizeof(h[0]), DESC)
int ASC(const void *c1,const void *c2){int tmp1=*(int *)c1;int tmp2=*(int *)c2;if(tmp1<tmp2){return -1;}if(tmp1==tmp2){return 0;}if(tmp1>tmp2){return 1;}}
int DESC(const void *c1,const void *c2){int tmp1 = *(int *)c1;int tmp2=*(int *)c2;if(tmp1>tmp2){return -1;}if(tmp1==tmp2){return  0;}if(tmp1<tmp2){return 1;}}
void Reverse(int *a, int *b, unsigned int n) {unsigned int i = 0;unsigned int d = n;while(d--) {b[d] = a[i++];}}

static ll p[101][101];
static int flag[101];
ll dp[101][101];
int n,m;
ll solve(int a, int b)
{
  int i;
  ll s = 0;
  if (dp[a][b] >= 0) {
    return dp[a][b];
  }
  if (a == b) {
    if (flag[a]) {
      return 0;
    }
    else {
      return 1;
    }
  }
  rep(i, n) {
    if (p[a][i]) s += solve(i, b) * p[a][i];
  }
  dp[a][b] = s;
  return dp[a][b];
}

int main(void)
{
  int i,j;
  int a,b,c;
  scanf("%d", &n);
  scanf("%d", &m);
  rep(i,m) {
    scanf("%d %d %d", &a, &b, &c);
    p[c - 1][a - 1] = b;
    flag[c - 1] = 1;
  }
  rep(i, 101) rep(j, 101) dp[i][j] = -1;
  rep(i, n - 1) printf("%lld\n", solve(n - 1, i));
  return 0;
}
0