結果

問題 No.1704 Many Bus Stops (easy)
ユーザー kotatsugamekotatsugame
提出日時 2021-10-08 22:17:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 1,113 bytes
コンパイル時間 545 ms
コンパイル使用メモリ 69,648 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-30 10:39:01
合計ジャッジ時間 4,109 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 69 ms
4,380 KB
testcase_02 AC 27 ms
4,376 KB
testcase_03 AC 28 ms
4,376 KB
testcase_04 AC 27 ms
4,380 KB
testcase_05 AC 27 ms
4,376 KB
testcase_06 AC 26 ms
4,380 KB
testcase_07 AC 27 ms
4,380 KB
testcase_08 AC 27 ms
4,376 KB
testcase_09 AC 27 ms
4,376 KB
testcase_10 AC 27 ms
4,376 KB
testcase_11 AC 27 ms
4,380 KB
testcase_12 AC 27 ms
4,376 KB
testcase_13 AC 27 ms
4,380 KB
testcase_14 AC 27 ms
4,380 KB
testcase_15 AC 26 ms
4,376 KB
testcase_16 AC 27 ms
4,376 KB
testcase_17 AC 27 ms
4,380 KB
testcase_18 AC 27 ms
4,380 KB
testcase_19 AC 26 ms
4,380 KB
testcase_20 AC 27 ms
4,380 KB
testcase_21 AC 27 ms
4,376 KB
testcase_22 AC 70 ms
4,380 KB
testcase_23 AC 71 ms
4,380 KB
testcase_24 AC 69 ms
4,380 KB
testcase_25 AC 71 ms
4,380 KB
testcase_26 AC 70 ms
4,376 KB
testcase_27 AC 71 ms
4,380 KB
testcase_28 AC 70 ms
4,376 KB
testcase_29 AC 71 ms
4,376 KB
testcase_30 AC 71 ms
4,380 KB
testcase_31 AC 69 ms
4,376 KB
testcase_32 AC 69 ms
4,376 KB
testcase_33 AC 70 ms
4,380 KB
testcase_34 AC 71 ms
4,376 KB
testcase_35 AC 70 ms
4,376 KB
testcase_36 AC 71 ms
4,380 KB
testcase_37 AC 69 ms
4,380 KB
testcase_38 AC 69 ms
4,376 KB
testcase_39 AC 71 ms
4,376 KB
testcase_40 AC 71 ms
4,376 KB
testcase_41 AC 70 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:36:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   36 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<atcoder/modint>
using namespace std;
using mint=atcoder::modint1000000007;
#include<array>
template<typename T,unsigned int N>
struct Matrix{
	array<array<T,N>,N>dat;
	array<T,N>&operator[](int i){return dat[i];}
	const array<T,N>&operator[](int i)const{return dat[i];}
	static Matrix eye(){
		Matrix res;
		for(int i=0;i<N;i++)res[i][i]=1;
		return res;
	}
	Matrix operator+(const Matrix&A)const{
		Matrix res;
		for(int i=0;i<N;i++)for(int j=0;j<N;j++)
			res[i][j]=dat[i][j]+A[i][j];
		return res;
	}
	Matrix operator*(const Matrix&A)const{
		Matrix res;
		for(int i=0;i<N;i++)for(int k=0;k<N;k++)for(int j=0;j<N;j++)
			res[i][j]+=dat[i][k]*A[k][j];
		return res;
	}
	Matrix pow(long long n)const{
		Matrix a=*this,res=eye();
		for(;n;a=a*a,n>>=1)if(n&1)res=res*a;
		return res;
	}
};
using mat=Matrix<mint,6>;
const mint inv3=mint(1)/3;
main()
{
	mat A;
	for(int i=3;i<6;i++)A[i-3][i]=1;
	for(int i=0;i<3;i++)
	{
		A[i][i]=inv3;
		for(int j=0;j<3;j++)if(i!=j)A[j+3][i]=inv3;
	}
	int T;cin>>T;
	for(;T--;)
	{
		int N;cin>>N;
		mat now=A.pow(N);
		cout<<now[0][0].val()<<"\n";
	}
}
0