QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#291161 | #3396. 数数 | MoRanSky | 100 ✓ | 29ms | 13400kb | C++23 | 2.0kb | 2023-12-26 05:09:01 | 2023-12-26 05:09:01 |
Judging History
answer
// Skyqwq
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long LL;
const int N = 2005, P = 1e9 + 7;
char s[N], g[N];
int n, m, tr[N][10], fail[N], idx, w[N], q[N], ans, f[N][N];
void insert() {
int p = 0;
for (int i = 1; g[i]; i++) {
int ch = g[i] - '0';
if (!tr[p][ch]) tr[p][ch] = ++idx;
p = tr[p][ch];
}
w[p] = 1;
}
void build() {
int hh = 1, tt = 0;
for (int i = 0; i < 10; i++)
if (tr[0][i]) q[++tt] = tr[0][i];
while (hh <= tt) {
int u = q[hh++];
for (int i = 0; i < 10; i++) {
int v = tr[u][i];
if (v) fail[v] = tr[fail[u]][i], q[++tt] = v, w[v] |= w[fail[v]];
else tr[u][i] = tr[fail[u]][i];
}
}
}
void work(int p, int c, int len) {
for (int i = 0; i < c; i++) {
if (len == n - 1 && i == 0) {
for (int j = 1; j < n; j++) {
for (int k = 1; k < 10; k++) {
int t = tr[0][k];
(ans += f[j - 1][t]) %= P;
}
}
continue;
}
int t = tr[p][i];
if (w[t]) continue;
(ans += f[len][t]) %= P;
}
}
void inline dp() {
int p = 0;
for (int i = 1; i <= n; i++) {
int c = s[i] - '0';
work(p, c, n - i);
p = tr[p][c];
if (w[p]) return;
}
(ans += 1) %= P;
}
int main() {
scanf("%s%d", s + 1, &m);
n = strlen(s + 1);
while (m--) {
scanf("%s", g + 1);
insert();
}
build();
for (int i = 0; i <= idx; i++) if (!w[i]) f[0][i] = 1;
for (int i = 1; i <= n; i++) {
for (int u = 0; u <= idx; u++) {
if (w[u]) continue;
for (int j = 0; j < 10; j++) {
int v = tr[u][j];
if (w[v]) continue;
(f[i][u] += f[i - 1][v]) %= P;
}
}
}
dp();
printf("%d\n", ans);
return 0;
}
详细
Test #1:
score: 10
Accepted
time: 0ms
memory: 3964kb
input:
206947 1 67
output:
198769
result:
ok single line: '198769'
Test #2:
score: 10
Accepted
time: 0ms
memory: 3976kb
input:
77785593 3 3611 1104 4176
output:
77661819
result:
ok single line: '77661819'
Test #3:
score: 10
Accepted
time: 0ms
memory: 3912kb
input:
399062529426653373 1 333333333
output:
459239962
result:
ok single line: '459239962'
Test #4:
score: 10
Accepted
time: 0ms
memory: 3956kb
input:
811485553573869808 1 444444444
output:
350483039
result:
ok single line: '350483039'
Test #5:
score: 10
Accepted
time: 0ms
memory: 3988kb
input:
168224238160073670 10 3001628491 855711872 37883641 432177802 858335865 6934525 94390 7861102 79161182 894566754
output:
343966707
result:
ok single line: '343966707'
Test #6:
score: 10
Accepted
time: 1ms
memory: 4264kb
input:
7929112705814828101384103592358573722715668795789363713831623173194977064596097955076510888310479577 50 5034 6480 701121 63396 3150 47228 6117 40340 60641 289046 948597 421753 8949 4756 231073 5997 97299 7637 3243 75818 179707 730406 478722 527445 15723 75400 818651 3022 830289 43630 1471 89832 2474...
output:
73760502
result:
ok single line: '73760502'
Test #7:
score: 10
Accepted
time: 1ms
memory: 4440kb
input:
4045288257690336172453650146085616379532431474946675426498348522249731554894906280713162044532618533 50 35675 286704 402459 568957 48540 4043 2060 9557 101350 77472 76010 31671 298463 1622 1513 5069 5481 447202 67245 211497 7595 29926 804206 79081 9968 870667 2511 319570 94507 892550 45813 23736 658...
output:
982386649
result:
ok single line: '982386649'
Test #8:
score: 10
Accepted
time: 26ms
memory: 13276kb
input:
571279210838771565159104720903725070059385081521577262830832257394247264080098678272217440048944097633622940126301697138509548213954371240283487542701965140910924313290797264291476335557921767206899907042626586230045737873982094761358554084758912245978059516851474982742850938515783694919027118434694...
output:
348545886
result:
ok single line: '348545886'
Test #9:
score: 10
Accepted
time: 24ms
memory: 13288kb
input:
537094012694199000076854839724749673063369009151960832006325718455103078745004774487534758170771882333531978774290238445342504390581939278433490074841444297945037980180950339844039276678365220697989801014534577037702559676355725230635713794080677012097576158464540596381989755928116140968453593152929...
output:
893576567
result:
ok single line: '893576567'
Test #10:
score: 10
Accepted
time: 29ms
memory: 13400kb
input:
966016145992883952621120290707664270333550519933470960254673653784764427094547042397527348368189735277457783135449224612507346545740715002313186395683448805857182307260587908325005672431479989923019279800100217464275144149348038438173081152050987158082692564000651613025582817850298836518581112024786...
output:
410051029
result:
ok single line: '410051029'