結果

問題 No.1111 コード進行
ユーザー keijakkeijak
提出日時 2020-07-10 22:11:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 2,490 bytes
コンパイル時間 1,974 ms
コンパイル使用メモリ 176,040 KB
実行使用メモリ 219,136 KB
最終ジャッジ日時 2024-04-19 17:23:08
合計ジャッジ時間 4,611 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,820 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 5 ms
6,940 KB
testcase_06 AC 6 ms
8,448 KB
testcase_07 AC 6 ms
7,552 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 5 ms
6,944 KB
testcase_10 AC 7 ms
10,112 KB
testcase_11 AC 3 ms
6,940 KB
testcase_12 AC 6 ms
8,576 KB
testcase_13 AC 4 ms
7,040 KB
testcase_14 AC 7 ms
10,880 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 7 ms
9,088 KB
testcase_17 AC 7 ms
10,496 KB
testcase_18 AC 3 ms
6,944 KB
testcase_19 AC 3 ms
6,944 KB
testcase_20 AC 4 ms
6,944 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 9 ms
12,672 KB
testcase_23 AC 4 ms
6,944 KB
testcase_24 AC 4 ms
7,808 KB
testcase_25 AC 9 ms
12,160 KB
testcase_26 AC 6 ms
7,808 KB
testcase_27 AC 3 ms
6,940 KB
testcase_28 AC 84 ms
111,360 KB
testcase_29 AC 38 ms
48,384 KB
testcase_30 AC 55 ms
75,008 KB
testcase_31 AC 10 ms
16,000 KB
testcase_32 AC 56 ms
67,456 KB
testcase_33 AC 39 ms
45,056 KB
testcase_34 AC 58 ms
81,280 KB
testcase_35 AC 79 ms
103,552 KB
testcase_36 AC 102 ms
110,080 KB
testcase_37 AC 32 ms
29,696 KB
testcase_38 AC 23 ms
22,784 KB
testcase_39 AC 65 ms
73,984 KB
testcase_40 AC 89 ms
101,248 KB
testcase_41 AC 93 ms
123,520 KB
testcase_42 AC 52 ms
51,968 KB
testcase_43 AC 42 ms
45,952 KB
testcase_44 AC 22 ms
26,368 KB
testcase_45 AC 62 ms
76,416 KB
testcase_46 AC 9 ms
8,448 KB
testcase_47 AC 197 ms
219,136 KB
testcase_48 AC 9 ms
8,576 KB
testcase_49 AC 8 ms
8,320 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:84:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   84 |       auto [p, q, c] = nextc[j];
      |            ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

const i64 MOD = 1'000'000'007;

struct mint {
  long long x;
  mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M, K;
  cin >> N >> M >> K;
  vector<tuple<int, int, int>> nextc;
  REP(i, M) {
    int p, q, c;
    cin >> p >> q >> c;
    p--;
    q--;
    nextc.emplace_back(p, q, c);
  }
  vector<vector<vector<mint>>> dp(
      N + 1, vector<vector<mint>>(300, vector<mint>(K + 1)));
  REP(j, 300) { dp[1][j][0] = 1; }
  for (int i = 2; i <= N; ++i) {
    REP(j, M) {
      auto [p, q, c] = nextc[j];
      REP(k, K + 1) {
        mint x = dp[i - 1][p][k];
        if (k + c <= K) dp[i][q][k + c] += x;
      }
    }
  }
  mint ans = 0;
  REP(j, 300) { ans += dp[N][j][K]; }
  cout << ans << endl;
}
0