답안 #503110

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
503110 2022-01-07T09:32:57 Z _tien_ 회문 (APIO14_palindrome) C++14
0 / 100
1000 ms 3808 KB
#include<bits/stdc++.h>
using namespace std;

#define maxn 300005

struct node{
  int startt,endd;
  int length;
  int insertEdg[26];
  int suffixEdg;
};

node root1,root2;
node tree[maxn];
int currNode,ans=1;
int dem[maxn];
string s;
int ptr;

void insertt(int idx){
int tmp=currNode;
while(true){
    int currLength=tree[tmp].length;
    if(idx-currLength>=1 && s[idx] == s[idx-currLength-1])
        break;
    tmp=tree[tmp].suffixEdg;
}
int x=tmp;
while(true){
    int currLength=tree[tmp].length;
    if(idx-currLength>=1 && s[idx] == s[idx-currLength-1])
        dem[tree[x].insertEdg[s[idx]-'a']]++;
    if(x==1||x==2)break;
    x=tree[x].suffixEdg;
}
if(tree[tmp].insertEdg[s[idx]-'a']!=0){
    currNode=tree[tmp].insertEdg[s[idx]-'a'];
    return ;
}
ptr++;dem[ptr]++;
tree[tmp].insertEdg[s[idx]-'a']=ptr;
tree[ptr].length=tree[tmp].length+2;
tree[ptr].endd=idx;
tree[ptr].startt=idx-tree[ptr].length+1;

tmp=tree[tmp].suffixEdg;

currNode=ptr;
if(tree[currNode].length==1){
    tree[currNode].suffixEdg=2;
    return;
}

while(true){
    int currLength=tree[tmp].length;
    if(idx-currLength>=1&&s[idx]==s[idx-currLength-1])
         break;
    tmp=tree[tmp].suffixEdg;
}
tree[currNode].suffixEdg=tree[tmp].insertEdg[s[idx]-'a'];

}
int main(){
    root1.length=-1;
    root1.suffixEdg=1;
    root2.length=0;
    root2.suffixEdg=1;

    tree[1]=root1;
    tree[2]=root2;
    ptr=2;
    currNode=1;
    cin>>s;
    for(int i=0;i<s.length();i++)
        insertt(i);
    for(int i=3;i<=ptr;i++)
        ans=max(ans,tree[i].length*dem[i]);
    cout<<ans;
    return 0;
}












Compilation message

palindrome.cpp: In function 'int main()':
palindrome.cpp:74:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |     for(int i=0;i<s.length();i++)
      |                 ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 288 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 312 KB Output is correct
10 Incorrect 0 ms 204 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 4 ms 332 KB Output is correct
4 Correct 1 ms 432 KB Output is correct
5 Correct 4 ms 332 KB Output is correct
6 Correct 5 ms 332 KB Output is correct
7 Correct 1 ms 440 KB Output is correct
8 Correct 3 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Incorrect 1 ms 204 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 195 ms 1456 KB Output is correct
2 Correct 111 ms 1464 KB Output is correct
3 Correct 352 ms 1560 KB Output is correct
4 Correct 256 ms 1508 KB Output is correct
5 Correct 2 ms 1484 KB Output is correct
6 Correct 10 ms 1472 KB Output is correct
7 Correct 39 ms 1476 KB Output is correct
8 Incorrect 1 ms 332 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1088 ms 3420 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1046 ms 3808 KB Time limit exceeded
2 Halted 0 ms 0 KB -