이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define ii pair < int , int >
#define iii pair < int , ii>
#define iv pair < ii , ii >
#define fi first
#define se second
#define y1 dkjfd
using namespace std;
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
const int base = 310;
int pre[N], pw[N];
int mul(int x, int y)
{
return 1LL * x * y % mod;
}
int add(int x, int y)
{
return ((1LL * x + y) % mod + mod) % mod;
}
int get(int l, int r)
{
return add(pre[r], - mul(pre[l - 1], pw[r - l + 1]));
}
main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("wormsort.in" , "r" , stdin);
// freopen("wormsort.out" , "w" , stdout);
pw[0] = 1;
for(int i = 1; i <= 1e6; i++)
pw[i] = mul(pw[i - 1], base);
int t; cin >> t;
while(t--)
{
string s; cin >> s;
int n = s.size();
s = '#' + s;
for(int i = 1; i <= n; i++)
pre[i] = add(mul(pre[i - 1], base), s[i]);
int ans = 0;
int i = 1;
int d = 1;
while(true)
{
while(get(i, i + d - 1) != get(n - i - d + 2, n - i + 1)) d++;
// cout << i << " " << d << endl;
if(i != n - i - d + 2) ans += 2;
else ans += 1;
i += d;
d = 1;
if(i > (n + 1) / 2) break;
}
cout << ans << '\n';
}
}
컴파일 시 표준 에러 (stderr) 메시지
palindromic.cpp:30:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
30 | main()
| ^~~~
# | 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... |