結果

問題 No.30 たこやき工場
ユーザー mudbdbmudbdb
提出日時 2015-07-29 20:46:37
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,934 bytes
コンパイル時間 1,007 ms
コンパイル使用メモリ 24,064 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-21 05:19:53
合計ジャッジ時間 1,059 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:76:18: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long long int’ [-Wformat=]
   76 |         printf("%d\n", total(no, N));
      |                 ~^     ~~~~~~~~~~~~
      |                  |     |
      |                  int   long long int
      |                 %lld
main.c:29:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |   scanf("%d", &N);
      |   ^~~~~~~~~~~~~~~
main.c:30:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |   scanf("%d", &M);
      |   ^~~~~~~~~~~~~~~
main.c:36:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |     scanf("%d", &(P[i]));
      |     ^~~~~~~~~~~~~~~~~~~~
main.c:37:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   37 |     scanf("%d", &(Q[i]));
      |     ^~~~~~~~~~~~~~~~~~~~
main.c:38:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   38 |     scanf("%d", &(R[i]));
      |     ^~~~~~~~~~~~~~~~~~~~

ソースコード

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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0