답안 #625149

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
625149 2022-08-09T13:43:03 Z Hanksburger 회문 (APIO14_palindrome) C++17
100 / 100
24 ms 35108 KB
#include <bits/stdc++.h>
using namespace std;
int nxt[300005][26], suff[300005], len[300005], freq[300005], cur=1, cnt=2;
string s;
void add(int x)
{
    while (s[x-len[cur]-1]!=s[x])
        cur=suff[cur];
    int y=s[x]-'a';
    if (nxt[cur][y])
    {
        cur=nxt[cur][y];
        freq[cur]++;
        return;
    }
    nxt[cur][y]=++cnt;
    len[cnt]=len[cur]+2;
    freq[cnt]++;
    if (len[cnt]==1)
    {
        suff[cnt]=2;
        cur=cnt;
        return;
    }
    do cur=suff[cur];
    while (s[x-len[cur]-1]!=s[x]);
    suff[cnt]=nxt[cur][y];
    cur=cnt;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    len[1]=-1;
    suff[1]=suff[2]=1;
    cin >> s;
    for (int i=0; i<s.length(); i++)
        add(i);
    long long ans=0;
    for (int i=cnt; i>=3; i--)
    {
        ans=max(ans, 1LL*freq[i]*len[i]);
        freq[suff[i]]+=freq[i];
    }
    cout << ans;
    return 0;
}

Compilation message

palindrome.cpp: In function 'int main()':
palindrome.cpp:38:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for (int i=0; i<s.length(); i++)
      |                   ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 1 ms 1508 KB Output is correct
5 Correct 1 ms 1492 KB Output is correct
6 Correct 1 ms 1492 KB Output is correct
7 Correct 1 ms 1508 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11988 KB Output is correct
2 Correct 9 ms 12000 KB Output is correct
3 Correct 8 ms 11988 KB Output is correct
4 Correct 8 ms 12004 KB Output is correct
5 Correct 8 ms 12000 KB Output is correct
6 Correct 6 ms 8916 KB Output is correct
7 Correct 8 ms 10180 KB Output is correct
8 Correct 2 ms 768 KB Output is correct
9 Correct 4 ms 3284 KB Output is correct
10 Correct 7 ms 10196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 35072 KB Output is correct
2 Correct 22 ms 34960 KB Output is correct
3 Correct 24 ms 34976 KB Output is correct
4 Correct 23 ms 35036 KB Output is correct
5 Correct 23 ms 35036 KB Output is correct
6 Correct 22 ms 31176 KB Output is correct
7 Correct 23 ms 29352 KB Output is correct
8 Correct 5 ms 1260 KB Output is correct
9 Correct 6 ms 1244 KB Output is correct
10 Correct 20 ms 28904 KB Output is correct
11 Correct 22 ms 35108 KB Output is correct
12 Correct 7 ms 4272 KB Output is correct