結果

問題 No.30 たこやき工場
ユーザー yuppe19 😺yuppe19 😺
提出日時 2017-07-01 14:55:36
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 895 bytes
コンパイル時間 344 ms
コンパイル使用メモリ 51,972 KB
最終ジャッジ日時 2024-04-27 02:27:08
合計ジャッジ時間 689 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:8:1: error: ‘vector’ does not name a type
    8 | vector<vector<edge>> G;
      | ^~~~~~
main.cpp:9:1: error: ‘vector’ does not name a type
    9 | vector<vector<i64>> dp;
      | ^~~~~~
main.cpp:10:1: error: ‘vector’ does not name a type
   10 | vector<bool> is_start;
      | ^~~~~~
main.cpp: In function ‘i64 rec(int, int)’:
main.cpp:14:14: error: ‘dp’ was not declared in this scope
   14 |   i64 &res = dp[u][v];
      |              ^~
main.cpp:18:16: error: ‘G’ was not declared in this scope
   18 |   for(edge e : G[u]) {
      |                ^
main.cpp: In function ‘int main()’:
main.cpp:26:3: error: ‘G’ was not declared in this scope
   26 |   G.assign(n, vector<edge>());
      |   ^
main.cpp:26:15: error: ‘vector’ was not declared in this scope
   26 |   G.assign(n, vector<edge>());
      |               ^~~~~~
main.cpp:3:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
    2 | #include <algorithm>
  +++ |+#include <vector>
    3 | using namespace std;
main.cpp:26:26: error: expected primary-expression before ‘>’ token
   26 |   G.assign(n, vector<edge>());
      |                          ^
main.cpp:26:28: error: expected primary-expression before ‘)’ token
   26 |   G.assign(n, vector<edge>());
      |                            ^
main.cpp:27:3: error: ‘is_start’ was not declared in this scope
   27 |   is_start.assign(n, true);
      |   ^~~~~~~~
main.cpp:35:3: error: ‘dp’ was not declared in this scope
   35 |   dp.assign(n, vector<i64>(n, -1));
      |   ^~
main.cpp:35:26: error: expected primary-expression before ‘>’ token
   35 |   dp.assign(n, vector<i64>(n, -1));
      |                          ^
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: warn

ソースコード

diff #

#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;
}
0