답안 #621139

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
621139 2022-08-03T12:51:35 Z socpite 회문 (APIO14_palindrome) C++14
100 / 100
63 ms 66624 KB
#include<bits/stdc++.h>
using namespace std;

#define f first
#define s second

typedef long long ll;

const int maxn = 3e5+5;

int cnt = 2;
int lnk[maxn], go[maxn][26], len[maxn];
ll dp[maxn];
ll ans = 0;
vector<int> tree[maxn];

string str;

void dfs(int x){
    for(auto v: tree[x]){
        dfs(v);
        dp[x]+=dp[v];
    }
    ans = max(ans, dp[x]*len[x]);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> str;
    str = '#'+str;
    len[0]=-1;
    len[1]=0;
    int crr = 1;
    for(int i = 1; i < str.length(); i++){
        int id = str[i]-'a';
        while(crr && str[i] != str[i-len[crr]-1])crr = lnk[crr];
        if(go[crr][id])crr = go[crr][id];
        else{
            int tmp = lnk[crr];
            while(tmp && str[i] != str[i-len[tmp]-1])tmp = lnk[tmp];
            if(!go[tmp][id])lnk[cnt]=1;
            else lnk[cnt]=go[tmp][id];
            go[crr][id]=cnt;
            len[cnt]=len[crr]+2;
            crr = cnt;
            cnt++;
        }
        dp[crr]++;
    }
    for(int i = 1; i < cnt; i++)tree[lnk[i]].push_back(i);
    dfs(0);
    cout << ans;
}

Compilation message

palindrome.cpp: In function 'int main()':
palindrome.cpp:36:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(int i = 1; i < str.length(); i++){
      |                    ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7380 KB Output is correct
2 Correct 5 ms 7396 KB Output is correct
3 Correct 5 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 5 ms 7380 KB Output is correct
6 Correct 8 ms 7380 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 5 ms 7380 KB Output is correct
12 Correct 5 ms 7400 KB Output is correct
13 Correct 4 ms 7376 KB Output is correct
14 Correct 5 ms 7380 KB Output is correct
15 Correct 5 ms 7380 KB Output is correct
16 Correct 4 ms 7380 KB Output is correct
17 Correct 6 ms 7380 KB Output is correct
18 Correct 5 ms 7380 KB Output is correct
19 Correct 4 ms 7380 KB Output is correct
20 Correct 4 ms 7380 KB Output is correct
21 Correct 4 ms 7380 KB Output is correct
22 Correct 4 ms 7380 KB Output is correct
23 Correct 4 ms 7380 KB Output is correct
24 Correct 5 ms 7380 KB Output is correct
25 Correct 5 ms 7380 KB Output is correct
26 Correct 7 ms 7380 KB Output is correct
27 Correct 5 ms 7380 KB Output is correct
28 Correct 6 ms 7380 KB Output is correct
29 Correct 4 ms 7380 KB Output is correct
30 Correct 4 ms 7380 KB Output is correct
31 Correct 4 ms 7380 KB Output is correct
32 Correct 4 ms 7336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7512 KB Output is correct
2 Correct 4 ms 7508 KB Output is correct
3 Correct 5 ms 7512 KB Output is correct
4 Correct 5 ms 7496 KB Output is correct
5 Correct 5 ms 7508 KB Output is correct
6 Correct 6 ms 7504 KB Output is correct
7 Correct 6 ms 7508 KB Output is correct
8 Correct 4 ms 7508 KB Output is correct
9 Correct 4 ms 7508 KB Output is correct
10 Correct 5 ms 7380 KB Output is correct
11 Correct 4 ms 7380 KB Output is correct
12 Correct 4 ms 7380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9044 KB Output is correct
2 Correct 6 ms 9044 KB Output is correct
3 Correct 7 ms 9308 KB Output is correct
4 Correct 6 ms 9300 KB Output is correct
5 Correct 7 ms 8660 KB Output is correct
6 Correct 6 ms 8788 KB Output is correct
7 Correct 6 ms 8896 KB Output is correct
8 Correct 4 ms 7384 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 5 ms 8276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 24772 KB Output is correct
2 Correct 17 ms 23748 KB Output is correct
3 Correct 19 ms 27128 KB Output is correct
4 Correct 38 ms 25384 KB Output is correct
5 Correct 17 ms 20420 KB Output is correct
6 Correct 15 ms 18000 KB Output is correct
7 Correct 20 ms 20484 KB Output is correct
8 Correct 6 ms 7744 KB Output is correct
9 Correct 8 ms 11984 KB Output is correct
10 Correct 17 ms 18384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 59588 KB Output is correct
2 Correct 45 ms 54492 KB Output is correct
3 Correct 52 ms 66624 KB Output is correct
4 Correct 47 ms 57616 KB Output is correct
5 Correct 63 ms 47556 KB Output is correct
6 Correct 39 ms 49332 KB Output is correct
7 Correct 38 ms 45752 KB Output is correct
8 Correct 16 ms 8360 KB Output is correct
9 Correct 9 ms 8284 KB Output is correct
10 Correct 49 ms 40236 KB Output is correct
11 Correct 47 ms 54888 KB Output is correct
12 Correct 12 ms 13356 KB Output is correct