結果

問題 No.1086 桁和の桁和2
ユーザー 沙耶花沙耶花
提出日時 2020-06-19 22:32:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,836 bytes
コンパイル時間 2,297 ms
コンパイル使用メモリ 211,632 KB
実行使用メモリ 9,084 KB
最終ジャッジ日時 2023-09-16 14:49:13
合計ジャッジ時間 10,057 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 142 ms
5,372 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 87 ms
4,876 KB
testcase_11 AC 24 ms
4,376 KB
testcase_12 AC 6 ms
4,380 KB
testcase_13 AC 111 ms
5,140 KB
testcase_14 AC 71 ms
4,664 KB
testcase_15 AC 1,763 ms
4,380 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

vector<int> Merge(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*10+j)%9;
			int D = mod(A[i]*B[j]);
			ret[nxt] = mod(ret[nxt] + D);
		}
	}
	return ret;
}

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> now = {2,1,1,1,1,1,1,1,1};
	vector<int> ret = {1,0,0,0,0,0,0,0,0};
	while(X!=0){
		if(X&1){
			ret = Merge(ret,now);
		}
		now = Merge(now,now);
		X/=2;
	}
	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++){
		auto x = calc(L[i],R[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