QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#689912 | #6522. Digit Mode | wcyQwQ | WA | 29ms | 4112kb | C++14 | 2.3kb | 2024-10-30 19:11:05 | 2024-10-30 19:11:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using arr = array<int, 10>;
const int N = 55, mod = 1e9 + 7, M = 12;
int c[N][N], f[M][N][N], g[M][N][N], mx;
bool dbg;
int calc(int n, arr &b) {
dbg = b[1] == 1;
memset(f, 0, sizeof f);
f[0][0][0] = 1;
for (int i = 0; i < 9; i++) {
for (int j = 0; j <= n; j++) {
for (int k = 0; k <= mx; k++) {
if (!f[i][j][k]) continue;
for (int l = 0; l <= n - j; l++) {
(f[i + 1][l + j][max(k, l + b[i])] += 1ll * f[i][j][k] * c[l + j][j] % mod) %= mod;
}
}
}
}
memset(g, 0, sizeof g);
g[10][0][0] = 1;
for (int i = 10; i >= 1; i--) {
for (int j = 0; j <= n; j++) {
for (int k = 0; k <= mx; k++) {
if (!g[i][j][k]) continue;
for (int l = 0; l <= n - j; l++) {
(g[i - 1][l + j][max(k, l + b[i - 1])] += 1ll * g[i][j][k] * c[l + j][j] % mod) %= mod;
}
}
}
}
for (int i = 0; i <= 10; i++) {
for (int j = 0; j <= n; j++) {
for (int k = 1; k <= mx; k++) {
(f[i][j][k] += f[i][j][k - 1]) %= mod;
(g[i][j][k] += g[i][j][k - 1]) %= mod;
}
}
}
int ans = 0;
for (int i = 1; i < 10; i++) {
for (int j = 0; j <= n; j++) {
int sum = 0;
for (int k = 0; k <= n - j; k++) {
(sum += 1ll * f[i][k][j + b[i]] * g[i + 1][n - j - k][j - 1 + b[i]] * c[n - j][k] % mod) %= mod;
}
(ans += 1ll * i * sum % mod * c[n][j] % mod) %= mod;
}
}
return ans;
}
void solve() {
string s;
cin >> s;
int n = s.size();
arr buc;
buc.fill(0);
int ans = 0;
for (int i = 1; i < n; i++) {
mx = i;
for (int j = 1; j < 10; j++) {
buc[j] = 1;
(ans += calc(i - 1, buc)) %= mod;
buc[j] = 0;
}
}
mx = n;
for (int i = 0; i < n; i++) {
for (int j = !i ? 1 : 0; j < s[i] - '0'; j++) {
buc[j]++;
(ans += calc(n - i - 1, buc)) %= mod;
buc[j]--;
}
buc[s[i] - '0']++;
}
(ans += calc(0, buc)) %= mod;
cout << ans << '\n';
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int T;
cin >> T;
for (int i = 0; i <= 50; i++) {
for (int j = 0; j <= i; j++) {
c[i][j] = !j ? 1 : (c[i - 1][j] + c[i - 1][j - 1]) % mod;
}
}
while (T--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3900kb
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: 2ms
memory: 3884kb
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: 3ms
memory: 3884kb
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: 3ms
memory: 3876kb
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: 4ms
memory: 3812kb
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: 4ms
memory: 3816kb
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: 4ms
memory: 3836kb
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: 12ms
memory: 3820kb
input:
3 5014252832385738 8762796162648653 919997886706385
output:
892033338 297722019 462512414
result:
ok 3 number(s): "892033338 297722019 462512414"
Test #9:
score: -100
Wrong Answer
time: 29ms
memory: 4112kb
input:
2 775701797726112292362823101 75927988177061355614
output:
956916846 566830847
result:
wrong answer 1st numbers differ - expected: '371275551', found: '956916846'