QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#771058 | #6234. 动物园 | Jay202 | 100 ✓ | 687ms | 94488kb | C++17 | 884b | 2024-11-22 09:25:09 | 2024-11-22 09:25:09 |
Judging History
answer
#include <iostream>
#include <cstring>
typedef long long ll;
const int LEN = 1'000'001;
const ll MOD = 1e9 + 7;
char S[LEN];
int T, dp[LEN], fail[LEN], p[LEN][21];
ll solve() {
ll ret = 1;
std::cin >> S;
memset(dp, 0, sizeof dp);
memset(fail, 0, sizeof fail);
memset(p, 0, sizeof p);
for (int i = 1, j = 0, k; S[i]; ++i) {
while (j && S[j] ^ S[i]) j = fail[j - 1];
if (S[j] == S[i]) {
p[i][0] = j;
fail[i] = ++j;
for (int d = 1; d < 21; ++d)
p[i][d] = p[p[i][d - 1]][d - 1];
}
k = i;
for (int d = 20; d >= 0; --d) {
if (p[k][d] + 1 > (i + 1) / 2)
k = p[k][d];
}
if (S[i] == S[p[k][0]]) ret = ret * (dp[p[k][0]] + 2) % MOD;
if (S[i] == S[p[i][0]]) dp[i] = dp[p[i][0]] + 1;
}
return ret;
}
int main() {
std::cin.tie(0)->sync_with_stdio(0);
std::cin >> T;
while (T--) std::cout << solve() << '\n';
}
详细
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 33ms
memory: 93488kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaxpuvf abababababababababababababababababababababababdgcd abcbaabcbaabcbaabcbaabcbaabcbaabcbaabcbaabcbafmlqh abacababacababacababacababacababacababacababadjyxq aabaacaabaacaabaacaabaacaabaacaabaacaabaacaabjtaxw
output:
592345761 371390093 121623872 675691877 481106999
result:
ok 5 number(s): "592345761 371390093 121623872 675691877 481106999"
Test #2:
score: 10
Accepted
time: 27ms
memory: 93668kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaavtgynkaevpdhsdwswilx ababababababababababababababababababababababababababababababababababababababababababababababababa...
output:
469770619 76547694 933305750 902388437 803348921
result:
ok 5 number(s): "469770619 76547694 933305750 902388437 803348921"
Test #3:
score: 10
Accepted
time: 27ms
memory: 93624kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaafcbwqryehhjfnlhglcnn ababababababababababababababababababababababababababababababababababababababababababababababababa...
output:
734885313 42387799 866611493 737798559 606697835
result:
ok 5 number(s): "734885313 42387799 866611493 737798559 606697835"
Test #4:
score: 10
Accepted
time: 33ms
memory: 93508kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
256900524 822524261 413461597 106784584 900200874
result:
ok 5 number(s): "256900524 822524261 413461597 106784584 900200874"
Test #5:
score: 10
Accepted
time: 37ms
memory: 94240kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
338653171 215976943 353365401 126668510 374446639
result:
ok 5 number(s): "338653171 215976943 353365401 126668510 374446639"
Test #6:
score: 10
Accepted
time: 79ms
memory: 93528kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
121054060 135829705 586084763 774583391 672914918
result:
ok 5 number(s): "121054060 135829705 586084763 774583391 672914918"
Test #7:
score: 10
Accepted
time: 131ms
memory: 93664kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
608896507 705745581 866882032 907283717 280168955
result:
ok 5 number(s): "608896507 705745581 866882032 907283717 280168955"
Test #8:
score: 10
Accepted
time: 321ms
memory: 93916kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
757739184 436599146 408735068 62286478 824797798
result:
ok 5 number(s): "757739184 436599146 408735068 62286478 824797798"
Test #9:
score: 10
Accepted
time: 677ms
memory: 94488kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
359993524 770772317 946742907 673664964 798002419
result:
ok 5 number(s): "359993524 770772317 946742907 673664964 798002419"
Test #10:
score: 10
Accepted
time: 687ms
memory: 94404kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
237665674 899763767 416501680 103496894 979807695
result:
ok 5 number(s): "237665674 899763767 416501680 103496894 979807695"
Extra Test:
score: 0
Extra Test Passed