# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
418969 | Dymo | 회문 (APIO14_palindrome) | C++14 | 1086 ms | 13444 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ull long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define pb push_back
//#define endl "\n"
const ll maxn =1e6+5;
const ll mod=988642507;
const ll base=317;
ull f[maxn];
ull fv[maxn];
ull mu[maxn];
ll n;
ll cntnw=0;
map<ull,ll> mp;
ll cnt[maxn];
ll len[maxn];
ll nxt[maxn];
ll in[maxn];
bool add(ull val,ll len1)
{
if (!mp.count(val))
{
cntnw++;
len[cntnw]=len1;
mp[val]=cntnw;
return true;
}
return false;
}
ull get(ll l,ll r)
{
return f[r]-f[l-1]*mu[r-l+1];
}
ull getv(ll l,ll r)
{
swap(l,r);
l=n-l+1;
r=n-r+1;
return fv[r]-fv[l-1]*mu[r-l+1];
}
bool chk(ll l,ll r)
{
ll len=(r-l+1)/2;
if(get(r-len+1,r)==getv(l,l+len-1)) return true;
return false;
}
ll val[maxn];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("t.inp","r"))
{
freopen("test.inp","r",stdin);
freopen("test.ans","w",stdout);
}
mt19937_64 rd(time(NULL));
mu[0]=1;
for (int i=1; i<maxn; i++)
mu[i]=(mu[i-1]*base);
for (int i=1; i<=26; i++)
{
val[i]=abs((ll)rd());
}
string s;
cin>> s;
string t=s;
n=s.length();
s=" "+ s;
for (int i=1; i<=n; i++)
{
f[i]=f[i-1]*base+val[s[i]-'a'+1];
}
reverse(t.begin(),t.end());
t=" "+t;
for (int i=1; i<=n; i++)
{
fv[i]=fv[i-1]*base+val[t[i]-'a'+1];
}
ll ans=0;
for (ll len=1;len<=n;len++)
{
mp.clear();
for (int i=1;i+len-1<=n;i++)
{
if (chk(i,i+len-1))
{
mp[get(i,i+len-1)]++;
ans=max(ans,mp[get(i,i+len-1)]*len);
}
}
}
cout <<ans<<endl;
}
컴파일 시 표준 에러 (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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |