QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#416905#4318. 高性能计算导论集群登录密码复杂性策略YeahPotatoAC ✓368ms25728kbC++142.5kb2024-05-22 10:39:352024-05-22 10:39:35

Judging History

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

  • [2024-05-22 10:39:35]
  • 评测
  • 测评结果:AC
  • 用时:368ms
  • 内存:25728kb
  • [2024-05-22 10:39:35]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
const int N = 1005;
int l, r, A, B, n, dp[N][36][26][2][3], s[N];
inline int R(int x, int y) { return (x += y) >= MOD ? x - MOD : x; }
inline void ADD(int &x, int y) { x = R(x, y); }
int qpow(int x, int y) {
	int t = 1;
	for (; y; y>>=1) {
		if (y & 1) t = 1ll * t * x % MOD;
		x = 1ll * x * x % MOD;
	} return t;
}
int m, p[N], _p[N], tmp[N];
void BM(int n, int *a) {
	int lst, _d, _m = 0; p[0] = _p[0] = MOD - 1;
	for (int i=0; i<=n; i++) {
		int d = a[i];
		for (int j=1; j<=m; j++)
			d = (d + 1ll * (MOD - p[j]) * a[i-j]) % MOD;
		if (! d) continue;
		if (! m) { m = i + 1, lst = i, _d = MOD - d; continue; }
		int coef = 1ll * d * qpow(_d, MOD - 2) % MOD;
		for (int j=1; j<=m; j++)
			tmp[j] = p[j];
		for (int j=0; j<=_m; j++)
			p[i-lst+j] = (p[i-lst+j] + 1ll * coef * _p[j]) % MOD;
		if (i - lst + _m > m) {
			int _ = m; m = i - lst + _m, lst = i, _d = MOD - d, _m = _;
			for (int j=1; j<=_; j++)
				_p[j] = tmp[j];
		}
	}
}
int x[N], t[N], c[N];
void mul(int * a, int * b) {
	for (int i=0; i<m; i++)
		for (int j=0; j<m; j++)
			c[i+j] = (c[i+j] + 1ll * a[i] * b[j]) % MOD;
	for (int i=m-1<<1; i>=m; i--)
		for (int j=m; ~j; j--)
			c[i-j] = (c[i-j] + 1ll * c[i] * p[j]) % MOD;
	for (int i=0; i<m; i++)
		a[i] = c[i], c[i] = 0;
}
int calc(int y) {
	memset (x, 0, sizeof x), memset (t, 0, sizeof t), x[1] = t[0] = 1;
	for (; y; y>>=1) {
		if (y & 1) mul(t, x);
		mul(x, x);
	} int res = 0;
	for (int i=0; i<m; i++)
		res = (res + 1ll * t[i] * s[i]) % MOD;
	return res;
}
int main() {
	cin >> l >> r >> A >> B;
	for (int j=0; j<=35; j++)
		dp[1][j][1][0][0] = 1 + (j > 9);
	for (int i=1; i<=1000; i++)
		for (int j=0; j<=35; j++)
			for (int k=1; k<26; k++)
				for (int f=0; f<=1; f++)
					for (int t=0; t<=2; t++)
						if (dp[i][j][k][f][t] && (! t && k < A || t && k < B)) {
							for (int x=0; x<=35; x++) {
								if (x == j)
									ADD(dp[i+1][x][!t?k+1:2][f][0], dp[i][j][k][f][t]);
								else if (x == j - 1 && x != 9)
									ADD(dp[i+1][x][t&1?k+1:2][f][1], dp[i][j][k][f][t]);
								else if (x == j + 1 && x != 10)
									ADD(dp[i+1][x][t&2?k+1:2][f][2], dp[i][j][k][f][t]);
								else
									ADD(dp[i+1][x][1][f|j>9^x>9][0], dp[i][j][k][f][t]);
								if (x > 9)
									ADD(dp[i+1][x][1][f|j>9^x>9][0], dp[i][j][k][f][t]);
							}
							if (f)
								s[i] = R(s[i], dp[i][j][k][f][t]);
						}
	for (int i=1; i<=1000; i++)
		s[i] = R(s[i], s[i-1]);
	BM(1000, s);
	cout << R(calc(r), MOD - calc(l - 1));
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 301ms
memory: 25588kb

input:

1 1 6 14

output:

0

result:

ok single line: '0'

Test #2:

score: 0
Accepted
time: 328ms
memory: 25584kb

input:

107140316 406944816 6 13

output:

192490578

result:

ok single line: '192490578'

Test #3:

score: 0
Accepted
time: 366ms
memory: 25720kb

input:

779830894 854589440 6 16

output:

142613425

result:

ok single line: '142613425'

Test #4:

score: 0
Accepted
time: 353ms
memory: 25664kb

input:

820947500 832029867 6 25

output:

334755990

result:

ok single line: '334755990'

Test #5:

score: 0
Accepted
time: 363ms
memory: 25648kb

input:

531362238 979634526 6 26

output:

628390760

result:

ok single line: '628390760'

Test #6:

score: 0
Accepted
time: 310ms
memory: 25644kb

input:

580120176 615170139 2 24

output:

282232431

result:

ok single line: '282232431'

Test #7:

score: 0
Accepted
time: 257ms
memory: 25640kb

input:

609381043 653379818 2 13

output:

803190890

result:

ok single line: '803190890'

Test #8:

score: 0
Accepted
time: 319ms
memory: 25728kb

input:

137169046 882295293 4 17

output:

487036819

result:

ok single line: '487036819'

Test #9:

score: 0
Accepted
time: 344ms
memory: 25648kb

input:

394493680 588692626 4 20

output:

99083012

result:

ok single line: '99083012'

Test #10:

score: 0
Accepted
time: 316ms
memory: 25728kb

input:

722139370 843455409 3 20

output:

187518918

result:

ok single line: '187518918'

Test #11:

score: 0
Accepted
time: 171ms
memory: 25664kb

input:

154981461 843412687 4 6

output:

799306362

result:

ok single line: '799306362'

Test #12:

score: 0
Accepted
time: 365ms
memory: 25636kb

input:

999999999 1000000000 6 15

output:

227192434

result:

ok single line: '227192434'

Test #13:

score: 0
Accepted
time: 114ms
memory: 25592kb

input:

892758405 994840518 4 4

output:

945734811

result:

ok single line: '945734811'

Test #14:

score: 0
Accepted
time: 357ms
memory: 25680kb

input:

536870911 973078527 6 14

output:

598094194

result:

ok single line: '598094194'

Test #15:

score: 0
Accepted
time: 368ms
memory: 25648kb

input:

536870912 973078527 6 15

output:

803373842

result:

ok single line: '803373842'

Test #16:

score: 0
Accepted
time: 335ms
memory: 25708kb

input:

333333333 333333333 6 14

output:

867976976

result:

ok single line: '867976976'

Test #17:

score: 0
Accepted
time: 21ms
memory: 25640kb

input:

66025887 800841810 2 2

output:

141443913

result:

ok single line: '141443913'

Test #18:

score: 0
Accepted
time: 159ms
memory: 25584kb

input:

37821660 191789705 5 5

output:

232561519

result:

ok single line: '232561519'

Test #19:

score: 0
Accepted
time: 281ms
memory: 25644kb

input:

668000825 930344057 6 9

output:

597839207

result:

ok single line: '597839207'

Test #20:

score: 0
Accepted
time: 303ms
memory: 25712kb

input:

692413584 717112316 6 10

output:

912537114

result:

ok single line: '912537114'