結果
| 問題 | No.30 たこやき工場 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-07-01 14:55:36 |
| 言語 | C++11(old_compat) (gcc 12.4.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 895 bytes |
| 記録 | |
| コンパイル時間 | 1,880 ms |
| コンパイル使用メモリ | 185,004 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2026-03-08 16:12:16 |
| 合計ジャッジ時間 | 2,415 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:25:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
25 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:30:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
30 | int a, c, b; scanf("%d%d%d", &a, &c, &b);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <iostream>
#include <algorithm>
using namespace std;
using i64 = long long;
struct edge { int to, cost; };
int n, m;
vector<vector<edge>> G;
vector<vector<i64>> dp;
vector<bool> is_start;
// uをひとつ作るのに必要なvの個数
i64 rec(int u, int v) {
i64 &res = dp[u][v];
if(res != -1) { return res; }
if(u == v) { return res = 1; }
res = 0;
for(edge e : G[u]) {
res += rec(e.to, v) * e.cost;
}
return res;
}
int main(void) {
scanf("%d%d", &n, &m);
G.assign(n, vector<edge>());
is_start.assign(n, true);
is_start[n-1] = false;
for(int i=0; i<m; ++i) {
int a, c, b; scanf("%d%d%d", &a, &c, &b);
--a, --b;
G[b].push_back(edge({a, c}));
is_start[b] = false;
}
dp.assign(n, vector<i64>(n, -1));
for(int i=0; i<n-1; ++i) {
i64 res = rec(n-1, i);
if(!is_start[i]) { res = 0; }
printf("%lld\n", res);
}
return 0;
}