結果

問題 No.1340 おーじ君をさがせ
ユーザー srjywrdnprkt
提出日時 2023-08-24 23:39:00
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 3,324 bytes
コンパイル時間 2,134 ms
コンパイル使用メモリ 200,988 KB
最終ジャッジ日時 2025-02-16 13:20:50
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 59
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll modc = 998244353;
class mint {
ll x;
public:
mint(ll x=0) : x((x%modc+modc)%modc) {}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint& a) {
if ((x += a.x) >= modc) x -= modc;
return *this;
}
mint& operator-=(const mint& a) {
if ((x += modc-a.x) >= modc) x -= modc;
return *this;
}
mint& operator*=(const mint& a) {
(x *= a.x) %= modc;
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;
}
mint inv() const {return pow(modc-2);}
mint& operator/=(const mint& a){ return (*this) *= a.inv();}
mint operator/(const mint& a) const {
mint res(*this);
return res/=a;
}
bool operator == (const mint& a) const{ return x == a.x;}
bool operator != (const mint& a) const{ return x != a.x;}
friend ostream& operator<<(ostream& os, const mint& m){
os << m.x;
return os;
}
friend istream& operator>>(istream& ip, mint &m) {
ll t;
ip >> t;
m = mint(t);
return ip;
}
ll val(){ return x;}
};
template<typename T>
using matrix = vector<vector<T>>;
template<typename T>
void show(matrix<T> &a){
for (int i=0; i<a.size(); i++){
for (int j=0; j<a[i].size(); j++) cout << a[i][j] << " ";
cout << endl;
}
}
template<typename T>
matrix<T> dot(matrix<T> &a, matrix<T> &b){
int N = a.size();
matrix<T> c(N, vector<T>(N));
for (int i=0; i<N; i++){
for (int k=0; k<N; k++){
for (int j=0; j<N; j++) c[i][j] |= a[i][k] & b[k][j];
}
}
return c;
}
template<typename T>
T det(matrix<T> a){
int N = a.size();
T res = 1;
for (int i=0; i<N; i++){
if (a[i][i] == 0){
for (int j=i+1; j<N; j++){
if (a[i][j] != 0){
swap(a[i], a[j]);
res *= -1;
break;
}
}
if (a[i][i] == 0) return 0;
}
res *= a[i][i];
T iv = (T) 1 / a[i][i];
for (int k=i; k<N; k++) a[i][k] *= iv;
for (int j=i+1; j<N; j++){
T mag = a[j][i];
for (int k=i; k<N; k++){
a[j][k] -= mag * a[i][k];
}
}
}
return res;
}
template<typename T>
matrix<T> pow(matrix<T> a, ll N){
int M = a.size();
matrix<T> b(M, vector<T>(M));
for (int i=0; i<M; i++) b[i][i] = 1;
while(N){
if (N % 2 == 1) b = dot(b, a);
N >>= 1;
a = dot(a, a);
}
return b;
}
int main(){
ll N, M, T, a, b, ans=0;
cin >> N >> M >> T;
matrix<ll> G(N, vector<ll>(N));
for (int i=0; i<M; i++){
cin >> a >> b;
G[b][a] = 1;
}
G = pow(G, T);
for (int i=0; i<N; i++) ans += G[i][0];
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0