結果

問題 No.1111 コード進行
ユーザー iqueue02iqueue02
提出日時 2020-07-10 22:41:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 1,128 bytes
コンパイル時間 2,573 ms
コンパイル使用メモリ 204,080 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 17:54:51
合計ジャッジ時間 4,187 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 5 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 6 ms
5,376 KB
testcase_26 AC 4 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 16 ms
5,376 KB
testcase_29 AC 18 ms
5,376 KB
testcase_30 AC 15 ms
5,376 KB
testcase_31 AC 4 ms
5,376 KB
testcase_32 AC 38 ms
5,376 KB
testcase_33 AC 18 ms
5,376 KB
testcase_34 AC 13 ms
5,376 KB
testcase_35 AC 23 ms
5,376 KB
testcase_36 AC 36 ms
5,376 KB
testcase_37 AC 37 ms
5,376 KB
testcase_38 AC 29 ms
5,376 KB
testcase_39 AC 24 ms
5,376 KB
testcase_40 AC 35 ms
5,376 KB
testcase_41 AC 21 ms
5,376 KB
testcase_42 AC 37 ms
5,376 KB
testcase_43 AC 28 ms
5,376 KB
testcase_44 AC 14 ms
5,376 KB
testcase_45 AC 23 ms
5,376 KB
testcase_46 AC 73 ms
5,376 KB
testcase_47 AC 75 ms
5,376 KB
testcase_48 AC 71 ms
5,376 KB
testcase_49 AC 71 ms
5,376 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