結果

問題 No.147 試験監督(2)
ユーザー 沙耶花沙耶花
提出日時 2021-10-28 18:17:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 814 ms / 2,000 ms
コード長 2,096 bytes
コンパイル時間 5,261 ms
コンパイル使用メモリ 265,968 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 13:05:36
合計ジャッジ時間 9,020 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 717 ms
5,248 KB
testcase_01 AC 814 ms
5,376 KB
testcase_02 AC 716 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template <class S,
          S (*op0)(S, S),
          S (*e0)(),
		  S (*op1)(S, S),
          S (*e1)()
          >
struct matrix{
	vector<vector<S>> v;
	int _h,_w;
	
	matrix(vector<vector<S>> X){
		v = X;
		_h = X.size();
		_w = 0;
		if(X.size()>0)_w = X[0].size();
	}
	
	matrix(int h,int w){
		v.resize(h,vector<S>(w,e0()));
		_h = h;
		_w = w;
	}
	
	void add_element(int from,int to,S x){
		v[to][from] = op0(v[to][from],x);
	}
	
	matrix e(){
		assert(_h==_w);
		matrix<S,op0,e0,op1,e1> ret(_h,_w);
		for(int i=0;i<_h;i++){
			for(int j=0;j<_w;j++){
				if(i==j)ret.v[i][j] = e1();
				else ret.v[i][j] = e0();
			}
		}
		return ret;
	}
	
	matrix &operator*=(const matrix &another){
		matrix<S,op0,e0,op1,e1> ret(_h,another._w);
		for(int i=0;i<_h;i++){
			for(int j=0;j<another._w;j++){
				ret.v[i][j] = e0();
				for(int k=0;k<_w;k++){
					ret.v[i][j] = op0(ret.v[i][j],op1(v[i][k],another.v[k][j]));
				}
			}
		}

		v = ret.v;
		return (*this);
	}
	
	matrix operator*(const matrix &another)const{
		return (matrix(*this)*=another);
	}
	
	matrix pow(long long cnt){
		matrix<S,op0,e0,op1,e1> ret = e();
		auto temp = *this;
		while(cnt!=0LL){
			if((cnt&1)==1){
				ret *= temp;
			}
			temp *= temp;
			cnt>>=1;
		}
		return ret;
	}
};

mint op0(mint a,mint b){
	return a+b;
}

mint e0(){
	return 0;
}

mint op1(mint a,mint b){
	return a*b;
}

mint e1(){
	return 1;
}

int main(){
	
	matrix<mint,op0,e0,op1,e1> M(2,2);
	M.add_element(0,0,1);
	M.add_element(0,1,1);
	M.add_element(1,0,1);
	
	int N;
	cin>>N;
	mint ans = 1;
	rep(_,N){
		long long C;
		cin>>C;
		
		auto temp = M.pow(C);
		
		matrix<mint,op0,e0,op1,e1> temp2(2,1);
		temp2.v[0][0] = 1;
		temp *= temp2;
		mint x = temp.v[0][0] + temp.v[1][0];

		string D;
		cin>>D;
		while(D.size()!=0){
			rep(i,D.back()-'0')ans *= x;
			D.pop_back();
			x = x.pow(10);
		}
		
	}
	
	cout<<ans.val()<<endl;
	
	return 0;
}
0