結果
問題 | No.1340 おーじ君をさがせ |
ユーザー |
![]() |
提出日時 | 2021-01-15 23:52:33 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 317 ms / 2,000 ms |
コード長 | 1,865 bytes |
コンパイル時間 | 4,312 ms |
コンパイル使用メモリ | 164,968 KB |
実行使用メモリ | 8,704 KB |
最終ジャッジ日時 | 2024-11-27 23:23:27 |
合計ジャッジ時間 | 9,718 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 59 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;using ld = long double;#define all(s) (s).begin(),(s).end()#define vcin(n) for(ll i=0;i<ll(n.size());i++) cin>>n[i]#define rever(vec) reverse(vec.begin(), vec.end())#define sor(vec) sort(vec.begin(), vec.end())#define fi first#define se secondconst ll mod = 998244353;//const ll mod = 1000000007;const ll inf = 2000000000000000000ll;static const long double pi = 3.141592653589793;template<class T,class U> void chmax(T& t,const U& u){if(t<u) t=u;}template<class T,class U> void chmin(T& t,const U& u){if(t>u) t=u;}ll modPow(ll a, ll n, ll mod) { ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }vector<vector<ll>> multi(vector<vector<ll>> a, vector<vector<ll>> b){ll n = a.size();vector<vector<ll>> res(n, vector<ll>(n, 0));for (ll i = 0; i < n; ++i){for (ll j = 0; j < n; ++j){for (ll x = 0; x < n; ++x){res[i][j] = ((res[i][j]) | (a[i][x] & b[x][j])) % mod;}}}return res;}vector<vector<ll>> mul_exp(vector<vector<ll>> adj, ll k, ll n){if (k == 0){vector<vector<ll>> d(n,vector<ll>(n));for(int i=0;i<n;i++){d[i][i]=1;}return d;}if (k == 1) return adj;vector<vector<ll>> res = mul_exp(adj, k / 2, n);if (k % 2 == 0) return multi(res, res);else return multi(adj, multi(res, res));}int main() {/* mod は 1e9+7 */ios::sync_with_stdio(false);std::cin.tie(nullptr);cout<< fixed << setprecision(10);ll n,m,t;cin>>n>>m>>t;vector<vector<ll>> dp(n,vector<ll>(n));for(int i=0;i<m;i++){ll x,y;cin>>x>>y;dp[y][x]=1;}auto ans=mul_exp(dp,t,n);ll ansi=0;for(int i=0;i<n;i++){ansi+=ans[i][0];}cout<<ansi<<endl;}