QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#694443#6522. Digit ModeShuishui#TL 1519ms4036kbC++142.9kb2024-10-31 17:57:592024-10-31 17:58:00

Judging History

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

  • [2024-10-31 17:58:00]
  • 评测
  • 测评结果:TL
  • 用时:1519ms
  • 内存:4036kb
  • [2024-10-31 17:57:59]
  • 提交

answer

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

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define Sz(x) (int)(x).size()
#define bit(x) (1ll << (x))
using ll = long long;
using db = double;
using ull = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vd = vector<db>;
mt19937 mrand(time(0));

const int mod = 1e9 + 7, CN = 1002;
ll inv[CN + 8], fac[CN + 8], ifac[CN + 8];

ll C(int a, int b) {
    if (b > a || b < 0) return 0;
    return fac[a] * ifac[b] % mod * ifac[a - b] % mod; 
}

void init() {
    inv[1] = fac[0] = ifac[0] = 1;
    for (int i = 2; i <= CN; i++) 
        inv[i] = (mod - mod / i) * inv[mod % i] % mod;
    for (int i = 1; i <= CN; i++)
        fac[i] = fac[i - 1] * i % mod, ifac[i] = ifac[i - 1] * inv[i] % mod;    
}

void add(ll &a, ll b)
{
	a += b;
	if (a >= mod) a -= mod;
	if (a < 0) a += mod;
}

ll fnum[2][52][52], fval[2][52][52];

void solve(void)
{
	string s;
	cin >> s;
	vi dig;
	int n = Sz(s);
	// cerr << n << "\n";
	for (int i = 0; i < n; i++)
		dig.pb(s[i] - '0');

	ll ans = 0;
	vi ad(10);


	auto calc = [&](int num)
	{
		int onum = num;
		num = n;
		for (int t = 0; t <= 1; t++)
			for (int a = 0; a <= num; a++)
				for (int b = 0; b <= num; b++)
					fnum[t][a][b] = fval[t][a][b] = 0;
		fnum[1][0][0] = 1;
		for (int i = 9; i >= 0; i--)
		{
			int u = i & 1, v = i & 1 ^ 1;

			for (int a = 0; a <= num; a++)
				for (int b = 0; b <= num; b++)
					fnum[v][a][b] = fval[v][a][b] = 0;

			for (int a = 0; a <= num; a++)
				for (int c = 0; c + a + ad[i] <= num && c + a <= onum; c++)
					for (int b = 0; b <= num; b++)
					{
						ll pnum = fnum[u][a][b], pval = fval[u][a][b];
						if (c + ad[i] > b)
						{
							add(fnum[v][a + c][c + ad[i]], pnum * C(onum - a, c) % mod);
							add(fval[v][a + c][c + ad[i]], pnum * C(onum - a, c) % mod * i % mod);
						}
						else
						{
							add(fnum[v][a + c][b], pnum * C(onum - a, c) % mod);
							add(fval[v][a + c][b], pval * C(onum - a, c) % mod);
						}
					}
		}
		// assert(fval[1][onum][0] == 0);
		for (int i = 0; i <= num; i++)
			add(ans, fval[1][onum][i]);
		
	};

	for (int i = 1; i < n; i++)
		for (int j = 1; j < 10; j++)
		{
			ad[j]++;
			calc(n - i - 1);
			ad[j]--;
		}

	for (int i = 0; i < n; i++)
	{
		for (int j = (i) ? 0 : 1; j < dig[i]; j++)
		{
			// cerr << j << "\n";
			ad[j]++;
			calc(n - i - 1);
			ad[j]--;
		}
		ad[dig[i]]++;
	}

	int mx = 0;
	for (int i = 1; i <= 9; i++)
		if (ad[i] >= ad[mx])
			mx = i;
	add(ans, mx);
	cout << ans << "\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	// cout << fixed << setprecision(10);
	init();
	int T = 1;
	cin >> T;
	for (int i = 1; i <= T; i++)
	solve();

	return 0;
}

详细

Test #1:

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

input:

5
9
99
999
99999
999999

output:

45
615
6570
597600
5689830

result:

ok 5 number(s): "45 615 6570 597600 5689830"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3676kb

input:

34
7
48
8
76
1
97
7
5
7
7
2
89
9
4
84
46
6
73
86
78
5
3
8
9
31
24
78
7
11
45
2
65
88
6

output:

28
236
36
420
1
597
28
15
28
28
3
525
45
10
484
221
21
399
500
435
15
6
36
45
145
104
435
28
47
215
3
341
516
21

result:

ok 34 numbers

Test #3:

score: 0
Accepted
time: 1ms
memory: 3992kb

input:

16
935
888
429
370
499
881
285
162
178
948
205
858
573
249
773
615

output:

6009
5618
2456
2078
2905
5562
1603
887
993
6121
1174
5378
3333
1374
4724
3631

result:

ok 16 numbers

Test #4:

score: 0
Accepted
time: 1ms
memory: 3736kb

input:

12
1242
9985
6469
9310
4191
9497
3166
3495
9711
9698
4137
2257

output:

7292
63531
37910
58047
23987
59479
18076
19675
61184
61086
23672
12913

result:

ok 12 numbers

Test #5:

score: 0
Accepted
time: 2ms
memory: 3704kb

input:

10
61195
72739
10164
79164
57851
12326
29132
55992
67377
13873

output:

337575
408170
63792
450686
316513
70493
157773
305011
374163
77954

result:

ok 10 numbers

Test #6:

score: 0
Accepted
time: 3ms
memory: 3736kb

input:

8
529983
127270
421121
291729
461233
695056
365028
271160

output:

2744573
687141
2160067
1500426
2359204
3705475
1851172
1381981

result:

ok 8 numbers

Test #7:

score: 0
Accepted
time: 5ms
memory: 3732kb

input:

7
7934351
8474057
1287369
5845624
7796773
5805755
7349121

output:

42465725
45668947
6716401
30094426
41554096
29861098
38756757

result:

ok 7 numbers

Test #8:

score: 0
Accepted
time: 41ms
memory: 3688kb

input:

3
5014252832385738
8762796162648653
919997886706385

output:

892033338
297722019
462512414

result:

ok 3 number(s): "892033338 297722019 462512414"

Test #9:

score: 0
Accepted
time: 163ms
memory: 3764kb

input:

2
775701797726112292362823101
75927988177061355614

output:

371275551
566830847

result:

ok 2 number(s): "371275551 566830847"

Test #10:

score: 0
Accepted
time: 1465ms
memory: 3832kb

input:

1
65760982925996012426370962570581226245366145016666

output:

661063035

result:

ok 1 number(s): "661063035"

Test #11:

score: 0
Accepted
time: 1498ms
memory: 3792kb

input:

1
62597468169905757754175023836706426691470692832490

output:

9983261

result:

ok 1 number(s): "9983261"

Test #12:

score: 0
Accepted
time: 1519ms
memory: 4036kb

input:

1
78912847369504885593964702297317051208901751786824

output:

817123221

result:

ok 1 number(s): "817123221"

Test #13:

score: -100
Time Limit Exceeded

input:

1
99999999999999999999999999999999999999999999999999

output:

25251932

result: