QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#359068#8303. Junior MathematiciankevinyangWA 61ms3688kbC++172.1kb2024-03-20 11:52:432024-03-20 11:52:44

Judging History

你现在查看的是最新测评结果

  • [2024-03-20 11:52:44]
  • 评测
  • 测评结果:WA
  • 用时:61ms
  • 内存:3688kb
  • [2024-03-20 11:52:43]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = (int)1e9+7;
int dp[5001][60][60];
vector<int>pw(5005);
int fix(int x, int m){
	x%=m; x+=m; x%=m;
	return x;
}
int find(int a, int b, int len, int m){
	int ans = 0;
	for(int i = 0; i<m; i++){
		for(int j = 0; j<m; j++){
			int na = a+i-b*j;
			na = fix(na,m);
			if(na==0)ans+=dp[len][i][j];
			ans%=mod;
		}
	}
	
	return ans;
}

int solve(string s, int m){
	int n = s.size();
	if(n==1)return 0;
	int ans = 0;
	dp[0][0][0] = 1;
	pw[0] = 1;
	for(int i = 1; i<=n+2; i++){
		pw[i] = pw[i-1]*10%m;
	}
	for(int i = 1; i<=n; i++){
		for(int a = 0; a<m; a++){ // a encodes x - f(x)
			for(int b = 0; b<m; b++){
				for(int d = 0; d<10; d++){
					int na = a + pw[i-1]*d - b*d; na = fix(na,m);
					int nb = (b+d)%m;
					dp[i][na][nb]+=dp[i-1][a][b];
					dp[i][na][nb]%=mod;
				}
			}
		}
	}
	for(int i = 1; i+1<n; i++){
		for(int d = 0; d<10; d++){
			int a = pw[i]*d%m;
			int b = d;
			ans+=find(a,b,i,m);
			ans%=mod;
		}
	}
	int a = 0; int b = 0;
	for(int i = 0; i<n; i++){
		for(int j = 0; j<=s[i]-'0'; j++){
			if(j==s[i]-'0' && i<n-1)continue;
			if(i==0&&j==0)continue;
			//cout << i << ' ' << j << '\n';
			int na = fix(a + pw[n-i-1]*j - b*j, m);
			int nb = (b+j)%m;
			//cout << na << ' ' << nb << '\n' << '\n';
			ans+=find(na,nb,n-i-1,m);
			//cout << ans << '\n';
			ans%=mod;
		}
		int d = s[i]-'0';
		a = fix(a + pw[n-i-1]*d - b*d, m);
		b = (b+d)%m;
	}
	for(int i = 0; i<=n; i++){
		for(int j = 0; j<m; j++){
			for(int k = 0; k<m; k++){
				dp[i][j][k] = 0;
			}
		}
	}
	return ans;
}
signed main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	int t;
	cin >> t;
	while(t--){
		string l,r;
		cin >> l >> r;
		int m;
		cin >> m;
		for(int i = (int)l.size()-1; i>=0; i--){
			if(l[i] == '0'){
				l[i] = '9';
				continue;
			}
			l[i]--;
			break;
		}
		if(l[0] == '0'){
			l.erase(l.begin());
		}
		int v = solve(r,m);
		v-=solve(l,m);
		v%=mod; v+=mod; v%=mod;
		cout << v << '\n';
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3688kb

input:

2
10
50
17
33
33
3

output:

2
1

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 61ms
memory: 3564kb

input:

1252
3893
6798
7
5883
8853
7
2999
4351
2
565
1767
7
1759
4751
10
79
8631
2
2128
8721
7
7890
8423
6
4708
7458
9
4501
6027
4
932
2708
2
3518
5859
7
4355
8296
3
2642
4470
10
7408
8939
8
4892
6777
7
4962
7976
6
2722
3171
7
6616
7527
6
7070
7612
5
429
2087
7
8786
8823
3
8831
8994
2
6346
8524
4
6026
8648
...

output:

505
447
767
155
357
5493
994
150
321
539
1158
388
1267
225
229
348
588
57
150
87
210
21
126
636
281
210
146
1538
635
152
476
709
966
173
275
29
253
48
1018
377
1349
503
646
43
980
685
563
1187
1
85
1
1037
38
16
1372
68
851
679
43
625
955
431
154
185
644
48
677
429
1218
80
518
258
34
281
36
721
148
2...

result:

wrong answer 4th lines differ - expected: '143', found: '155'