結果

問題 No.1086 桁和の桁和2
ユーザー 沙耶花沙耶花
提出日時 2020-06-19 22:39:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 301 ms / 3,000 ms
コード長 1,752 bytes
コンパイル時間 2,577 ms
コンパイル使用メモリ 209,256 KB
実行使用メモリ 5,672 KB
最終ジャッジ日時 2023-09-29 23:46:42
合計ジャッジ時間 8,574 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 140 ms
5,580 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 88 ms
4,696 KB
testcase_11 AC 25 ms
4,380 KB
testcase_12 AC 6 ms
4,380 KB
testcase_13 AC 112 ms
5,096 KB
testcase_14 AC 71 ms
4,388 KB
testcase_15 AC 38 ms
4,376 KB
testcase_16 AC 210 ms
4,932 KB
testcase_17 AC 19 ms
4,376 KB
testcase_18 AC 291 ms
5,296 KB
testcase_19 AC 239 ms
5,116 KB
testcase_20 AC 31 ms
4,376 KB
testcase_21 AC 207 ms
4,744 KB
testcase_22 AC 291 ms
5,444 KB
testcase_23 AC 178 ms
4,820 KB
testcase_24 AC 124 ms
4,392 KB
testcase_25 AC 245 ms
5,100 KB
testcase_26 AC 201 ms
4,752 KB
testcase_27 AC 145 ms
4,376 KB
testcase_28 AC 121 ms
4,380 KB
testcase_29 AC 135 ms
4,552 KB
testcase_30 AC 298 ms
5,664 KB
testcase_31 AC 299 ms
5,352 KB
testcase_32 AC 301 ms
5,380 KB
testcase_33 AC 299 ms
5,328 KB
testcase_34 AC 300 ms
5,460 KB
testcase_35 AC 142 ms
5,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000LL

int beki(int a,long long b,int M = modulo){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=((long long)x*a)%M;
		}
		a=((long long)a*a)%M;
		b>>=1;
	}
	return x;
}


int gyakugen(int a){
	return beki(a,modulo-2);
}

vector<int> Merge2(vector<int> A,vector<int> B){
	vector<int> ret(9,0);
	for(int i=0;i<A.size();i++){
		for(int j=0;j<B.size();j++){
			int nxt = (i+j)%9;
			int D = mod(A[i]*B[j]);
			ret[nxt] = mod(ret[nxt] + D);
		}
	}
	return ret;
}

vector<int> calc(long long X){
	vector<int> ret(9,0);
	if(X==0)return ret;
	int t = beki(10,X);
	t = mod(t - 1);
	t = mod(t * gyakugen(9));
	for(int i=0;i<9;i++)ret[i] = t;
	return ret;
}

vector<int> calc(long long L,long long R){
	vector<int> ret = calc(R);
	vector<int> t = calc(L);
	for(int i=0;i<ret.size();i++)ret[i] = mod(ret[i] - t[i]);
	ret[0] = mod(ret[0] + 1);
	return ret;
}

int main(){
	
	int N;
	cin>>N;
	deque<long long> L(N),R(N);
	deque<int> D(N);
	for(int i=0;i<N;i++)cin>>L[i];
	for(int i=0;i<N;i++)cin>>R[i];
	for(int i=0;i<N;i++)cin>>D[i];
	
	while(D.size()>0&&D.front()==0){
		D.pop_front();
		L.pop_front();
		R.pop_front();
	}
	
	if(D.size()==0){
		cout<<1<<endl;
		return 0;
	}
	N = D.size();
	bool zero = false;
	for(int i=0;i<N;i++){
		if(D[i]==0)zero=true;
	}
	if(zero){
		cout<<0<<endl;
		return 0;
	}

	vector<int> now = {1,0,0,0,0,0,0,0,0};
	for(int i=0;i<N;i++){
		now = Merge2(now,calc(L[i],R[i]));
		for(int j=0;j<9;j++){
			if(j!=D[i]%9)now[j] = 0;
		}
		if(D[i]==9&&i==0){
			now[0] = mod(now[0] - 1);
		}
	}
	
	int ans= 0;
	for(int i=0;i<now.size();i++)ans =mod(ans + now[i]);
	
	cout<<ans<<endl;
	
	return 0;
}
0