QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#217694 | #793. Palindromic Partitions | _LAP_ | 0 | 6ms | 9696kb | C++14 | 1.1kb | 2023-10-17 10:19:02 | 2023-10-17 10:19:04 |
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10, BASE = 13331, MOD = 1e9 + 7;
inline int Plus(int a, int b) {return a + b >= MOD ? a + b - MOD : a + b; }
inline int Minus(int a, int b) {return a - b < 0 ? a - b + MOD : a - b; }
int n, Hash[N], base[N]; char s[N];
inline int calc(int l, int r) {
return Minus(Hash[r], 1ll * Hash[l - 1] * base[r - l + 1] % MOD);
}
inline void solve() {
cin >> (s + 1); n = strlen(s + 1);
Hash[0] = 0;
for(int i = 1; i <= n; i ++)
Hash[i] = Plus(1ll * Hash[i - 1] * BASE % MOD, s[i]);
int res = 0;
for(int i = 1, j = n, len = 1; ; ) {
if(i + len - 1 >= j - len + 1) {res ++; break; }
if(calc(i, i + len - 1) == calc(j - len + 1, j)) {
res += 2, i += len, j -= len, len = 1;
continue;
} else {
len ++; continue;
}
}
cout << res << '\n';
}
int main() {
ios::sync_with_stdio(false), cin.tie(0);
base[0] = 1;
for(int i = 1; i <= 1000000; i ++)
base[i] = 1ll * base[i - 1] * BASE % MOD;
int T; cin >> T;
while(T --) solve();
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 6ms
memory: 9696kb
input:
10 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaabaaaaaaaaaaaaaab aaaaaaaaaaaaabxaaaaaaaaaaaaab baaaaaaaaaaaaaabaaaaaaaaaaaaaa aabbaabbaabbaaaaaaaabbaabbaabb ababababababababababababababab abcabcabcabcabcabcabcabcabcabc abcabcabcabcabccbacbacbacbacba qntshryhcojkqnlmqeob...
output:
31 29 3 3 3 13 15 11 31 3
result:
wrong answer 1st lines differ - expected: '30', found: '31'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%