| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 393316 | rumen_m | Palindromic Partitions (CEOI17_palindromic) | C++17 | 1 ms | 332 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
# include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;
const int base = 27;
const int maxn = 1e6+5;
int hashes[maxn];
int poww[maxn];
int find_hash(int from, int to)
{
int pref = (hashes[from-1]*poww[to-from+1])%MOD;
int ans = (hashes[to]+MOD-pref)%MOD;
return ans;
}
void solve()
{
string s;
cin>>s;
int ans = 0;
poww[0] = 1;
hashes[0] = 0;
int i;
for(i = 1; i<=s.size();i++)
{
int ch = s[i-1]-'a'+1;
poww[i] = (poww[i-1]*base)%MOD;
hashes[i] = (hashes[i-1]*base + ch)%MOD;
}
int prev = 1;
int from = 1;
int last = s.size();
int endd = s.size();
bool fl = false;
while(from<last)
{
if(find_hash(prev,from)==find_hash(last,endd))
{
fl = false;
ans+=2;
// cout<<" "<<from<<endl;
prev = from+1;
endd = last-1;
from++;
last--;
continue;
}
fl = true;
from++;
last--;
}
if(fl||from==last)ans++;
cout<<ans<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin>>t;
while(t--)
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
| # | 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... | ||||
