이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
using ll = long long;
using ii = pair<int,int>;
const int INF = 1e9;
const ll LLINF = 1e18;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int tc;
cin >> tc;
while (tc--) {
string s;
cin >> s;
int n = s.size();
ll B = 239, M = 1e9+7;
vector<ll> p(n+1), hs(n+1);
p[0] = 1; hs[0] = 0;
for (int i = 0; i < n; i++) {
p[i+1] = (p[i] * B) % M;
hs[i+1] = (hs[i] * B + s[i]) % M;
}
int l = 0, r = n, ans = 0;
while (l < r) {
int k = 1;
while (hs[l+k] - (hs[l] * p[k]) % M != hs[r] - (hs[r-k] * p[k]) % M) {
k++;
}
if (r-l == k) {
ans++;
break;
}
else ans += 2;
l += k;
r -= k;
}
cout << ans << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |