結果
問題 | No.1340 おーじ君をさがせ |
ユーザー |
![]() |
提出日時 | 2023-09-07 20:14:24 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 93 ms / 2,000 ms |
コード長 | 1,940 bytes |
コンパイル時間 | 5,250 ms |
コンパイル使用メモリ | 310,396 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-25 14:00:38 |
合計ジャッジ時間 | 8,117 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 59 |
ソースコード
#include<bits/stdc++.h>using namespace std;#include <atcoder/all>using namespace atcoder;using mint=modint998244353; //1000000007;using ll=long long;using pp=pair<ll,ll>;#define sr string#define vc vector#define fi first#define se second#define rep(i,n) for(ll i=0;i<(ll)n;i++)#define pb push_back#define all(v) v.begin(),v.end()#define pque priority_queue#define bpc(a) __builtin_popcount(a)// https://youtu.be/ylWYSurx10A?t=2352template<typename T>struct Matrix {int h, w;vector<vector<T>> d;Matrix() {}Matrix(int h, int w, T val=0): h(h), w(w), d(h, vector<T>(w,val)) {}Matrix& unit() {assert(h == w);rep(i,h) d[i][i] = 1;return *this;}const vector<T>& operator[](int i) const { return d[i];}vector<T>& operator[](int i) { return d[i];}Matrix operator*(const Matrix& a) const {assert(w == a.h);Matrix r(h, a.w);rep(i,h)rep(k,w)rep(j,a.w) {r[i][j] |= d[i][k]*a[k][j];}return r;}Matrix pow(long long t) const {assert(h == w);if (!t) return Matrix(h,h).unit();if (t == 1) return *this;Matrix r = pow(t>>1);r = r*r;if (t&1) r = r*(*this);return r;}// https://youtu.be/-j02o6__jgs?t=11273/* mint onlymint det() {assert(h == w);mint res = 1;rep(k,h) {for (int i = k; i < h; ++i) {if (d[i][k] == 0) continue;if (i != k) {swap(d[i],d[k]);res = -res;}}if (d[k][k] == 0) return 0;res *= d[k][k];mint inv = mint(1)/d[k][k];rep(j,h) d[k][j] *= inv;for (int i = k+1; i < h; ++i) {mint c = d[i][k];for (int j = k; j < h; ++j) d[i][j] -= d[k][j]*c;}}return res;}//*/};int main(){int n,m; ll t;cin>>n>>m>>t;Matrix<int>v(n,n);rep(i,m){int a,b;cin>>a>>b;v[b][a]=1;}v=v.pow(t);int ans=0;rep(i,n)ans+=v[i][0];cout<<ans;}