結果

問題 No.1111 コード進行
ユーザー chocono2230chocono2230
提出日時 2020-07-10 22:02:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,491 bytes
コンパイル時間 1,760 ms
コンパイル使用メモリ 180,480 KB
実行使用メモリ 4,704 KB
最終ジャッジ日時 2023-08-01 17:57:59
合計ジャッジ時間 8,279 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll 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 {
    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 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 {
    mint res(*this);
    return res/=a;
  }
};

int main(){
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<pair<int, int>>> gr(m, vector<pair<int, int>>());
  rep(i, m){
    int p, q, c;
    cin >> p >> q >> c;
    p--; q--;
    gr.at(p).push_back(make_pair(q, c));
  }
  vector<vector<mint>> dp(m, vector<mint>(k+1, 0));
  rep(i, m){
    if(gr.at(i).size() > 0) dp.at(i).at(0) = 1;
  }
  rep(t, n-1){
    // rep(i, k+1){
    //   rep(j, n) cerr << dp.at(j).at(i).x << " ";
    //   cerr << endl;
    // }
    // cerr << endl;
    vector<vector<mint>> nxdp(m, vector<mint>(k+1, 0));
    rep(i, m){
      for(auto p : gr.at(i)){
        rep(j, k-p.second+1){
          nxdp.at(p.first).at(j+p.second) += dp.at(i).at(j);
        }
      }
    }
    dp = nxdp;
  }
  mint ans = 0;
  rep(i, n){
    ans += dp.at(i).at(k);
  }
  cout << ans.x << endl;
  return 0;
}
0