結果

問題 No.1340 おーじ君をさがせ
ユーザー 沙耶花沙耶花
提出日時 2021-01-15 21:48:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,483 bytes
コンパイル時間 2,392 ms
コンパイル使用メモリ 210,408 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-17 19:43:40
合計ジャッジ時間 5,829 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 WA -
testcase_12 AC 4 ms
4,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 29 ms
4,376 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 10 ms
4,380 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 19 ms
4,380 KB
testcase_22 AC 47 ms
4,376 KB
testcase_23 AC 21 ms
4,380 KB
testcase_24 AC 85 ms
4,376 KB
testcase_25 AC 7 ms
4,376 KB
testcase_26 AC 5 ms
4,376 KB
testcase_27 AC 4 ms
4,380 KB
testcase_28 AC 7 ms
4,380 KB
testcase_29 AC 4 ms
4,376 KB
testcase_30 AC 20 ms
4,376 KB
testcase_31 AC 87 ms
4,376 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 5 ms
4,376 KB
testcase_38 AC 86 ms
4,380 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 2 ms
4,508 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 22 ms
4,384 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 20 ms
4,376 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 AC 2 ms
4,380 KB
testcase_57 AC 2 ms
4,380 KB
testcase_58 AC 2 ms
4,380 KB
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000

template <typename T,typename F0,typename F1>
struct matrix{
	F0 func0;
	F1 func1;
	vector<vector<T>> value;
	int height,width;
	T init_value0,init_value1;
	
	matrix(vector<vector<T>> X,F0 f0,F1 f1,T iv0,T iv1):func0(f0),func1(f1){
		height = X.size();
		width = X[0].size();
		value = X;
		init_value0 = iv0,init_value1 = iv1;
	}
	
	matrix(int h,int w,F0 f0,F1 f1,T iv0,T iv1):func0(f0),func1(f1){
		vector<vector<T>> d(h,vector<T>(w,iv0));
		height = h,width = w;
		value = d;
		init_value0 = iv0,init_value1 = iv1;
	}
	
	
	void set_1(){
		for(int i=0;i<height;i++){
			for(int j=0;j<width;j++){
				if(i==j)value[i][j] = init_value1;
				else value[i][j]=init_value0;
			}
		}
	}
	
	void show(){
		for(int i=0;i<height;i++){
			for(int j=0;j<width;j++){
				if(j!=0)cout<<' ';
				cout<<value[i][j];
			}
			cout<<endl;
		}
	}
	
	matrix &operator=(const matrix &another){
		value = another.value;
		height = another.height;
		width = another.width;
		return *this;
	}
	
	matrix &operator*=(const matrix &another){
		matrix<T,decltype(func0),decltype(func1)> R(height,another.width,func0,func1,init_value0,init_value1);
		for(int i=0;i<R.value.size();i++){
			for(int j=0;j<R.value[i].size();j++){
				R.value[i][j]=init_value0;
				for(int k=0;k<width;k++){
					R.value[i][j] = func0(R.value[i][j],func1(value[i][k],another.value[k][j]));
				}
			}
		}

		value = R.value;
		return (*this);
	}
	
	matrix operator*(const matrix &another)const{
		return (matrix(*this)*=another);
	}
	
	matrix beki(long long cnt){
		matrix<T,decltype(func0),decltype(func1)> R(height,width,func0,func1,init_value0,init_value1);
		R.set_1();
		auto temp = *this;
		while(cnt!=0LL){
			if(cnt%2==1){
				R *= temp;
			}
			temp *= temp;
			cnt/=2;
		}
		return R;
	}
};

int main(){
	
	int N,M;
	cin>>N>>M;
	long long T;
	cin>>T;
	
	vector<vector<int>> A(N+1,vector<int>(N+1,0));
	rep(i,M){
		int a,b;
		cin>>a>>b;
		A[a][b] = 1;
	}
	rep(i,N){
		A[i][N] = 1;
		A[N][N] = 1;
	}
	
	auto f0 = [](int a,int b){
		return a|b;
	};
	
	auto f1 = [](int a,int b){
		return a&b;
	};
	
	matrix<int,decltype(f0),decltype(f1)> AA(A,f0,f1,0LL,1);
	
	AA = AA.beki(T);
	
	vector<vector<int>> X(1,vector<int>(N+1,1));
	matrix<int,decltype(f0),decltype(f1)> XX(X,f0,f1,0LL,1);
	
	XX *= AA;
	
	int ans= 0;
	rep(i,N){
		ans += XX.value[0][i];
	}
	
	cout<<ans<<endl;
	
    return 0;
}
0