結果

問題 No.1111 コード進行
ユーザー yukudoyukudo
提出日時 2020-07-10 22:33:12
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 2,402 bytes
コンパイル時間 1,623 ms
コンパイル使用メモリ 170,084 KB
実行使用メモリ 225,512 KB
最終ジャッジ日時 2024-04-19 17:46:04
合計ジャッジ時間 8,436 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
225,392 KB
testcase_01 AC 180 ms
225,292 KB
testcase_02 AC 89 ms
225,352 KB
testcase_03 AC 85 ms
225,332 KB
testcase_04 AC 88 ms
225,404 KB
testcase_05 AC 85 ms
225,232 KB
testcase_06 AC 86 ms
225,356 KB
testcase_07 AC 89 ms
225,436 KB
testcase_08 AC 86 ms
225,344 KB
testcase_09 AC 85 ms
225,468 KB
testcase_10 AC 87 ms
225,292 KB
testcase_11 AC 86 ms
225,364 KB
testcase_12 AC 87 ms
225,456 KB
testcase_13 AC 85 ms
225,400 KB
testcase_14 AC 88 ms
225,328 KB
testcase_15 AC 86 ms
225,452 KB
testcase_16 AC 87 ms
225,228 KB
testcase_17 AC 87 ms
225,352 KB
testcase_18 AC 87 ms
225,368 KB
testcase_19 AC 89 ms
225,436 KB
testcase_20 AC 87 ms
225,332 KB
testcase_21 AC 87 ms
225,512 KB
testcase_22 AC 90 ms
225,420 KB
testcase_23 AC 87 ms
225,212 KB
testcase_24 AC 90 ms
225,420 KB
testcase_25 AC 90 ms
225,352 KB
testcase_26 AC 88 ms
225,228 KB
testcase_27 AC 87 ms
225,444 KB
testcase_28 AC 140 ms
225,496 KB
testcase_29 AC 111 ms
225,288 KB
testcase_30 AC 135 ms
225,260 KB
testcase_31 AC 94 ms
225,352 KB
testcase_32 AC 138 ms
225,232 KB
testcase_33 AC 123 ms
225,224 KB
testcase_34 AC 127 ms
225,408 KB
testcase_35 AC 138 ms
225,316 KB
testcase_36 AC 140 ms
225,428 KB
testcase_37 AC 102 ms
225,224 KB
testcase_38 AC 106 ms
225,304 KB
testcase_39 AC 156 ms
225,384 KB
testcase_40 AC 176 ms
225,404 KB
testcase_41 AC 144 ms
225,268 KB
testcase_42 AC 112 ms
225,452 KB
testcase_43 AC 132 ms
225,448 KB
testcase_44 AC 98 ms
225,236 KB
testcase_45 AC 122 ms
225,492 KB
testcase_46 AC 89 ms
225,208 KB
testcase_47 AC 191 ms
225,220 KB
testcase_48 AC 90 ms
225,384 KB
testcase_49 AC 87 ms
225,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

const ll MOD = 1e9 + 7;

struct mint {
  ll x;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  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 {mint res(*this);return res+=a;}
  mint operator-(const mint a) const {mint res(*this);return res-=a;}
  mint operator*(const mint a) const {mint res(*this);return res*=a;}
  mint pow(ll b) const {
    mint res(1), a(*this);
    while (b) {
      if (b & 1) res *= a;
      a *= a;
      b >>= 1;
    }
    return res;
  }
  // 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 {mint res(*this);return res/=a;}
};
ostream& operator<<(ostream& os, const mint& a) {os << a.x; return os;}


mint dp[305][305][305];

int main2() {

  const int V = 300;

  REP(i, 305) REP(j, 305) REP(k, 305) dp[i][j][k] = 0;

  int N = nextLong();
  int M = nextLong();
  int K = nextLong();

  vector< vector< pair<int, int>> > g(V);
  REP(m, M) {
    int P = nextLong() - 1;
    int Q = nextLong() - 1;
    int C = nextLong();
    g[P].push_back({Q, C});
  }

  REP(i, V) dp[1][i][0] += 1;

  for (int i = 1; i < N; i++) {
    for (int k = 0; k <= K; k++) {
      for (int m = 0; m < V; m++) {
        mint cur = dp[i][m][k];
        if (cur.x == 0) continue;
        for (auto e : g[m]) {
          if (k + e.second <= K) {
            dp[i+1][e.first][k + e.second] += cur;
          }
        }
      }
    }
  }

  mint ans = 0;
  REP(i, V) ans += dp[N][i][K];
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}
0