結果
| 問題 |
No.1111 コード進行
|
| コンテスト | |
| ユーザー |
le_panda_noir
|
| 提出日時 | 2020-07-19 13:32:38 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 267 ms / 2,000 ms |
| コード長 | 1,534 bytes |
| コンパイル時間 | 1,180 ms |
| コンパイル使用メモリ | 91,424 KB |
| 最終ジャッジ日時 | 2025-01-12 00:49:51 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 48 |
ソースコード
#include <iostream>
#include <vector>
#include <map>
using namespace std;
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)
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) {
edge[from][to] = 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 MInt& n) const { return MInt(val) += n; }
MInt& operator+=(const MInt& n) { val = (val + n.val) % MOD; return *this; }
friend ostream& operator<<(ostream& os, const MInt& n) { os<<n.val; return os; }
};
constexpr int MOD = 1e9+7;
using mint = MInt<MOD>;
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);
}
vector<vector<mint>> memo(300, vector<mint>(301));
rep(i, 300) {
memo[i][0] = 1;
}
rep(n, N-1) {
vector<vector<mint>> memo2(300, vector<mint>(301));
rep(from, 300) rep(k, K+1)
for (const auto& [to, c] : G[from]) {
if (k-c >= 0)
memo2[from][k] += memo[to][k-c];
}
swap(memo2, memo);
}
mint ans = 0;
rep(from, 300)
ans += memo[from][K];
cout << ans << endl;
return 0;
}
le_panda_noir