結果

問題 No.1111 コード進行
ユーザー iqueue02iqueue02
提出日時 2020-07-10 22:41:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 1,128 bytes
コンパイル時間 2,262 ms
コンパイル使用メモリ 208,060 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-01 18:44:53
合計ジャッジ時間 4,977 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 3 ms
4,384 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 4 ms
4,384 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 6 ms
4,376 KB
testcase_26 AC 5 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 19 ms
4,380 KB
testcase_29 AC 20 ms
4,380 KB
testcase_30 AC 17 ms
4,384 KB
testcase_31 AC 4 ms
4,380 KB
testcase_32 AC 41 ms
4,384 KB
testcase_33 AC 20 ms
4,384 KB
testcase_34 AC 16 ms
4,380 KB
testcase_35 AC 26 ms
4,380 KB
testcase_36 AC 41 ms
4,384 KB
testcase_37 AC 41 ms
4,380 KB
testcase_38 AC 31 ms
4,380 KB
testcase_39 AC 29 ms
4,380 KB
testcase_40 AC 39 ms
4,380 KB
testcase_41 AC 23 ms
4,384 KB
testcase_42 AC 40 ms
4,380 KB
testcase_43 AC 29 ms
4,384 KB
testcase_44 AC 17 ms
4,376 KB
testcase_45 AC 24 ms
4,380 KB
testcase_46 AC 78 ms
4,380 KB
testcase_47 AC 76 ms
4,384 KB
testcase_48 AC 78 ms
4,380 KB
testcase_49 AC 77 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int mod = 1e9 + 7;
constexpr int CMAX = 300;
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<P>> g(300);

  rep(i,m) {
    int p, q, c;
    cin >> p >> q >> c;
    p--; q--;
    g[p].emplace_back(make_pair(q, c));
  }

  vector<vector<int>> dp(300, vector<int>(CMAX + 1, 0));
  
  for (int u = 0; u < 300; u++) {
    for (auto p : g[u]) {
      int v = p.first;
      int cost = p.second;
      dp[v][cost]++;
    }
  }
  for (int i = 0; i < n - 2; i++) {

    vector<vector<int>> ndp(300, vector<int>(CMAX + 1, 0));


    for (int u = 0; u < 300; u++) {
      for (auto p : g[u]) {
        int v = p.first;
        int cost = p.second;

        for (int j = 0; j <= CMAX; j++) {
          if (j + cost <= CMAX) (ndp[v][j + cost] += dp[u][j]) %= mod; 
        }
      }
    }
    swap(dp, ndp);
  }

  int res = 0;
  for (int i = 0; i < 300; i++) (res += dp[i][k]) %= mod;
  cout << res << endl;
  return 0;
} 
0