QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#388680#6731. Digit ProductEcec243AC ✓160ms3644kbC++232.3kb2024-04-13 18:03:282024-04-13 18:03:29

Judging History

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

  • [2024-04-13 18:03:29]
  • 评测
  • 测评结果:AC
  • 用时:160ms
  • 内存:3644kb
  • [2024-04-13 18:03:28]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FILL(a, b) memset(a, b, sizeof(a))

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

const int mod = 1000000007;
const int LOG = 30;

void updAdd(int& x, int val) {
	x += val;
	if (x >= mod - 1) {
		x -= mod - 1;
	}
}

int mult(int a, int b) {
	return (LL)a * b % mod;
}

void updMult(int& x, int val) {
	x = mult(x, val);
}

int binPow(int a, int n) {
	int res = 1;
	while (n) {
		if (n & 1) {
			res = mult(res, a);
		}
		a = mult(a, a);
		n >>= 1;
	}
	return res;
}

int dpCnt[LOG][2][2], dpProd[LOG][2][2];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t;
	cin >> t;
	while (t--) {
		int l, r;
		cin >> l >> r;
		vector<int> dl, dr;
		while (l > 0) {
			dl.push_back(l % 10);
			l /= 10;
		}
		while (r > 0) {
			dr.push_back(r % 10);
			r /= 10;
		}
		while (SZ(dl) < SZ(dr)) {
			dl.push_back(0);
		}
		reverse(ALL(dl));
		reverse(ALL(dr));
		FOR(i, 0, LOG) {
			FOR(vl, 0, 2) {
				FOR(vr, 0, 2) {
					dpCnt[i][vl][vr] = 0;
					dpProd[i][vl][vr] = 1;
				}
			}
		}
		FOR(d, max(1, dl[0]), dr[0] + 1) {
			dpCnt[0][d == dl[0]][d == dr[0]]++;
			updMult(dpProd[0][d == dl[0]][d == dr[0]], d);
		}
		if (dl[0] == 0) {
			FOR(i, 1, SZ(dl)) {
				FOR(d, max(1, dl[i]), 10) {
					dpCnt[i][d == dl[i]][0]++;
					updMult(dpProd[i][d == dl[i]][0], d);
				}
				if (dl[i] != 0) {
					break;
				}
			}
		}
		FOR(pos, 0, SZ(dl) - 1) {
			FOR(vl, 0, 2) {
				FOR(vr, 0, 2) {
					int cnt = dpCnt[pos][vl][vr];
					if (cnt == 0) {
						continue;
					}
					FOR(d, vl ? dl[pos + 1] : 0, vr ? dr[pos + 1] + 1 : 10) {
						int nvl = vl && (d == dl[pos + 1]), nvr = vr && (d == dr[pos + 1]);
						updAdd(dpCnt[pos + 1][nvl][nvr], cnt);
						updMult(dpProd[pos + 1][nvl][nvr], mult(dpProd[pos][vl][vr], binPow(d, cnt)));
					}
				}
			}
		}
		int ans = 1;
		FOR(vl, 0, 2) {
			FOR(vr, 0, 2) {
				updMult(ans, dpProd[SZ(dl) - 1][vl][vr]);
			}
		}
		cout << ans << "\n";
	}
	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3528kb

input:

2
1 9
97 99

output:

362880
367416

result:

ok 2 number(s): "362880 367416"

Test #2:

score: 0
Accepted
time: 160ms
memory: 3644kb

input:

100000
657483518 657483518
296765674 296765675
500554849 500554849
392403 392411
962255578 962255578
35428433 35428436
362396272 362396273
284893570 974440644
115568436 806300808
751214641 751214647
646086592 646086598
437591523 437591526
263956058 263956059
558669721 558669723
655489691 655489692
2...

output:

806400
410944971
0
0
1512000
155233636
998375151
0
0
414306437
0
208997103
0
129273888
911603819
243342348
649464275
0
0
0
0
722813914
4320
11337408
653184
787649465
0
652380550
189496944
4608
0
26880
0
0
99347696
311040
0
208177374
0
16458092
489888
51840
0
888464445
0
933120
0
0
0
748384125
483840...

result:

ok 100000 numbers