結果

問題 No.1111 コード進行
ユーザー le_panda_noirle_panda_noir
提出日時 2020-07-19 13:21:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 3,888 bytes
コンパイル時間 1,613 ms
コンパイル使用メモリ 119,892 KB
実行使用メモリ 241,896 KB
最終ジャッジ日時 2023-08-22 09:54:23
合計ジャッジ時間 4,880 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
109,980 KB
testcase_01 AC 24 ms
109,800 KB
testcase_02 AC 24 ms
109,636 KB
testcase_03 AC 25 ms
109,956 KB
testcase_04 AC 24 ms
109,964 KB
testcase_05 AC 24 ms
109,696 KB
testcase_06 AC 25 ms
110,028 KB
testcase_07 AC 25 ms
109,672 KB
testcase_08 AC 24 ms
109,864 KB
testcase_09 AC 25 ms
109,704 KB
testcase_10 AC 25 ms
109,988 KB
testcase_11 AC 25 ms
109,964 KB
testcase_12 AC 26 ms
109,696 KB
testcase_13 AC 28 ms
109,680 KB
testcase_14 AC 28 ms
109,904 KB
testcase_15 AC 24 ms
109,984 KB
testcase_16 AC 25 ms
109,836 KB
testcase_17 AC 24 ms
109,972 KB
testcase_18 AC 24 ms
109,744 KB
testcase_19 AC 24 ms
109,960 KB
testcase_20 AC 24 ms
109,820 KB
testcase_21 AC 25 ms
109,636 KB
testcase_22 AC 24 ms
109,796 KB
testcase_23 AC 24 ms
109,864 KB
testcase_24 AC 24 ms
109,860 KB
testcase_25 AC 26 ms
109,844 KB
testcase_26 AC 27 ms
109,720 KB
testcase_27 AC 24 ms
109,836 KB
testcase_28 AC 23 ms
110,096 KB
testcase_29 AC 25 ms
111,900 KB
testcase_30 AC 51 ms
110,296 KB
testcase_31 AC 24 ms
109,848 KB
testcase_32 AC 66 ms
110,828 KB
testcase_33 AC 85 ms
110,264 KB
testcase_34 AC 23 ms
110,024 KB
testcase_35 AC 23 ms
109,968 KB
testcase_36 AC 25 ms
110,524 KB
testcase_37 AC 26 ms
111,636 KB
testcase_38 AC 66 ms
118,428 KB
testcase_39 AC 140 ms
111,272 KB
testcase_40 AC 154 ms
122,904 KB
testcase_41 AC 24 ms
109,696 KB
testcase_42 AC 29 ms
114,884 KB
testcase_43 AC 126 ms
121,420 KB
testcase_44 AC 25 ms
110,076 KB
testcase_45 AC 24 ms
110,024 KB
testcase_46 AC 28 ms
113,372 KB
testcase_47 AC 29 ms
113,372 KB
testcase_48 AC 82 ms
241,896 KB
testcase_49 AC 25 ms
110,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using vi = vector<int>;

#define in(v) v; cin >> v;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rrep(i,n) for(long long i=(n);i>=0;--i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

// ========== debug ==========
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(size_t i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
ostream& operator<<(ostream& os,const vector<char>&v){for(size_t i=0;i<v.size();++i)os<<v[i];return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
void debug2() {cerr << "\n";}
template<class First> void debug2(const First& first) {cerr<<first<<" ";}
template<class First, class... Rest> void debug2(const First& first, const Rest&... rest) {cerr<<first<<" ";debug2(rest...);}
#else
#define debug(...) 42
#define debug2(...) 42
#endif
// ===========================

struct Graph {
  vector<map<int, long long>> edge;
  Graph(int n = 0) { resize(n); }
  void resize(int n) {
    edge.resize(n, map<int, long long>());
  }
  void addEdge(int from, int to, long long weight, bool directed = false) {
    edge[from][to] = weight;
    if (!directed)
      edge[to][from] = weight;
  }
  map<int, long long>& operator[](int from) { return edge[from]; }
};
template<int MOD> struct MInt {
  long long val;
  constexpr MInt(long long val = 0) : val(val % MOD) { if (val < 0) val += MOD; }
  MInt operator-() const { return MInt(-val); }
  MInt operator+(const MInt& n) const { return MInt(val) += n; }
  MInt operator-(const MInt& n) const { return MInt(val) -= n; }
  MInt operator*(const MInt& n) const { return MInt(val) *= n; }
  MInt operator/(const MInt& n) const { return MInt(val) /= n; }
  MInt& operator+=(const MInt& n) { val = (val + n.val) % MOD; return *this; }
  MInt& operator-=(const MInt& n) { val = (MOD + val - n.val) % MOD; return *this; }
  MInt& operator*=(const MInt& n) { val = (val * n.val) % MOD; return *this; }
  MInt& operator/=(const MInt& n) { val = (*this * n.inv()).val; return *this; }
  bool operator==(const MInt& n) { return val == n.val; }
  bool operator!=(const MInt& n) { return val != n.val; }
  MInt pow(long long n) const {
    MInt pow = val, ans = 1;
    for (long long p = n; p > 0; p >>= 1, pow *= pow)
      if (p & 1) ans *= pow;
    return ans;
  }
  MInt inv() const { return pow(MOD-2); }
  friend ostream& operator<<(ostream& os, const MInt& n) { os<<n.val; return os; }
  friend istream& operator>>(istream& os, MInt& n) { os>>n.val; return os; }
};
constexpr int MOD = 1e9+7;
// constexpr int MOD = 998244353;
using mint = MInt<MOD>;


bool visited[300][301][301];
mint memo[300][301][301];
mint dfs(Graph &G, int start, int n, int k) {
  if (n == 0)
    return k == 0;
  if (k < 0)
    return 0;
  if (visited[start][n][k])
    return memo[start][n][k];
  visited[start][n][k] = true;
  mint ans = 0;
  for (const auto& [to, c] : G[start]) {
    ans += dfs(G, to, n-1, k-c);
  }
  return memo[start][n][k] = ans;
}
int main() {
  int N, M, K;
  ins(N, M, K);

  Graph G(300);
  rep(i, M) {
    int P, Q, C;
    ins(P, Q, C);
    --P, --Q;
    G.addEdge(P, Q, C, true);
  }
  mint ans = 0;
  rep(i, 300) {
    ans += dfs(G, i, N-1, K);
  }
  cout << ans << endl;

  return 0;
}
0