QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#771063 | #6234. 动物园 | Jay202 | 0 | 672ms | 94476kb | C++17 | 798b | 2024-11-22 09:27:45 | 2024-11-22 09:27:46 |
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;
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: 0
Wrong Answer
time: 0ms
memory: 5716kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaxpuvf abababababababababababababababababababababababdgcd abcbaabcbaabcbaabcbaabcbaabcbaabcbaabcbaabcbafmlqh abacababacababacababacababacababacababacababadjyxq aabaacaabaacaabaacaabaacaabaacaabaacaabaacaabjtaxw
output:
592345761 941231326 175433768 153356305 707561686
result:
wrong answer 2nd numbers differ - expected: '371390093', found: '941231326'
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 5744kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaavtgynkaevpdhsdwswilx ababababababababababababababababababababababababababababababababababababababababababababababababa...
output:
469770619 374028320 652685853 875433444 909239529
result:
wrong answer 2nd numbers differ - expected: '76547694', found: '374028320'
Test #3:
score: 0
Wrong Answer
time: 1ms
memory: 7832kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaafcbwqryehhjfnlhglcnn ababababababababababababababababababababababababababababababababababababababababababababababababa...
output:
734885313 410605202 305371699 609429184 606159686
result:
wrong answer 2nd numbers differ - expected: '42387799', found: '410605202'
Test #4:
score: 0
Wrong Answer
time: 5ms
memory: 6508kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
256900524 22225885 108883547 222754029 547367257
result:
wrong answer 2nd numbers differ - expected: '822524261', found: '22225885'
Test #5:
score: 0
Wrong Answer
time: 6ms
memory: 10136kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
338653171 156944560 165831331 246112448 895945273
result:
wrong answer 2nd numbers differ - expected: '215976943', found: '156944560'
Test #6:
score: 0
Wrong Answer
time: 50ms
memory: 16972kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
121054060 508256210 13637029 435560365 690790288
result:
wrong answer 2nd numbers differ - expected: '135829705', found: '508256210'
Test #7:
score: 0
Wrong Answer
time: 105ms
memory: 23164kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
608896507 391308942 988641689 978134105 411067504
result:
wrong answer 2nd numbers differ - expected: '705745581', found: '391308942'
Test #8:
score: 0
Wrong Answer
time: 305ms
memory: 53356kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
757739184 993106925 749900666 819680688 392967531
result:
wrong answer 2nd numbers differ - expected: '436599146', found: '993106925'
Test #9:
score: 0
Wrong Answer
time: 672ms
memory: 94464kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
359993524 329611176 907727294 608706824 767319741
result:
wrong answer 2nd numbers differ - expected: '770772317', found: '329611176'
Test #10:
score: 0
Wrong Answer
time: 655ms
memory: 94476kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
237665674 411257686 482691926 594896800 887691845
result:
wrong answer 2nd numbers differ - expected: '899763767', found: '411257686'