답안 #220183

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
220183 2020-04-07T08:34:35 Z LittleFlowers__ 회문 (APIO14_palindrome) C++14
0 / 100
1000 ms 26072 KB
#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0);
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))
#define gg exit(0);

const int N=300010;

int n,gap,ret;
int pos[N],sa[N],tmp[N],lcp[N],ln[N];
int f[22][N];
string s;

int cmp(int i,int j){
    if(pos[i]!=pos[j]) return pos[i]<pos[j];
    i+=gap, j+=gap;
    return i<=n && j<=n ? pos[i]<pos[j] : i>j;
}

int que(int i,int j){
    int t=ln[j-i+1];
    return min(f[t][i],f[t][j-(1<<t)+1]);
}


int calc(int l,int r){
    int lf=pos[l],rt=pos[l];
    int le=pos[l],ri=n,mi;
    while(le<=ri){
        mi=(le+ri)/2;
        if(que(pos[l],mi-1)>=r-l+1) rt=mi, le=mi+1;
        else ri=mi-1;
    }
    le=1,ri=pos[l];
    while(le<=ri){
        mi=(le+ri)/2;
        if(que(mi,pos[l]-1)>=r-l+1) lf=mi, ri=mi-1;
        else le=mi+1;
    }
    return (r-l+1) * (rt-lf+1);
}

main(){
    #define task "palindrome"
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    fasty;

    cin>>s; n=s.size(); s=" "+s;

    forinc(i,1,n) sa[i]=i, pos[i]=s[i];
    for(gap=1;;gap+=gap){
        sort(sa+1,sa+n+1,cmp);
        forinc(i,1,n-1) tmp[i+1]=tmp[i]+cmp(sa[i],sa[i+1]);
        forinc(i,1,n) pos[sa[i]]=tmp[i]+1;
        if(tmp[n]==n-1) break;
    }
    for(int i=1,k=0;i<=n;++i){
        for(int j=sa[pos[i]+1];s[i+k]==s[j+k];) k++;
        lcp[pos[i]]=k;
        if(k) k--;
    }

    forinc(i,1,n) f[0][i]=lcp[i];
    forinc(j,1,20) forinc(i,1,n){
        if(i+(1<<j)>n+1) continue;
        f[j][i]=min(f[j-1][i],f[j-1][i+(1<<j-1)]);
    }

    forinc(i,1,n){
        int l=i, r=i;
        while(l && r<=n && s[l]==s[r]){
            ret=max(ret,calc(l,r));
            l--, r++;
        }
        if(s[i]==s[i+1]){
            l=i, r=i+1;
            while(l && r<=n && s[l]==s[r]){
                ret=max(ret,calc(l,r));
                l--, r++;
            }
        }
    }
    cout<<ret;
}

Compilation message

palindrome.cpp:58:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
palindrome.cpp: In function 'int main()':
palindrome.cpp:82:45: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
         f[j][i]=min(f[j-1][i],f[j-1][i+(1<<j-1)]);
                                            ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Incorrect 5 ms 384 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 33 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 1152 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1095 ms 8564 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1096 ms 26072 KB Time limit exceeded
2 Halted 0 ms 0 KB -