답안 #433553

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
433553 2021-06-20T06:10:24 Z misir 회문 (APIO14_palindrome) C++14
100 / 100
30 ms 37236 KB
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 100005
#define tc prllf("Case %d: ", cs)
#define tcn prllf("Case %d:\n", cs);
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);


#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define siii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld %lld",&x,&y)
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define ss(ch) scanf("%s",ch)
#define pi(x) printf("%d",x)
#define pii(x,y) printf("%d %d",x,y)
#define piii(x,y,z) printf("%d %d %d",x,y,z)
#define pl(x) printf("%lld",x)
#define pll(x,y) printf("%lld %lld",x,y)
#define plll(x,y,z) printf("%lld %lld %lld",x,y,z)
#define ps(ch) printf("%s",ch)
#define F(i,a,b)      for(int i= a; i <= b; i++)
#define R(i,b,a)      for(int i= b; i >= a; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define sline(a) scanf("%[^\n]s",a)
#define Case(t) printf("Case %d:\n",t)

const int N = 300005;
int tree[N][26], link[N], id, t;
ll len[N], freq[N];
char str[N];

void extend(int p)
{
    while (str[p - len[t] - 1] != str[p]) t = link[t];
    int x = link[t];
    while (str[p - len[x] - 1] != str[p]) x = link[x];
    int c = str[p] - 'a';
    if (!tree[t][c])
    {
        tree[t][c] = ++id;
        len[id] = len[t] + 2;
        link[id] = len[id] == 1 ? 2 : tree[x][c];
    }
    t = tree[t][c];
    freq[t]++;
}

int main()
{
    /*
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
    //*/

    int l = scanf("%s", str + 1);
    l = strlen(str + 1);

    len[1] = -1, link[1] = 1;
    len[2] = 0, link[2] = 1;
    id = t = 2;

   for(int i = 1; i <= l; i++) extend(i);

    ll m = 0;
    for(int i = id; i >= 3; i--) {
        freq[link[i]] += freq[i];
        m = max(m, freq[i] * len[i]);
    }
    printf("%lld\n", m);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 0 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 2 ms 1484 KB Output is correct
4 Correct 2 ms 1484 KB Output is correct
5 Correct 2 ms 1484 KB Output is correct
6 Correct 2 ms 1484 KB Output is correct
7 Correct 1 ms 1484 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 12492 KB Output is correct
2 Correct 10 ms 12492 KB Output is correct
3 Correct 10 ms 12492 KB Output is correct
4 Correct 10 ms 12492 KB Output is correct
5 Correct 13 ms 12472 KB Output is correct
6 Correct 8 ms 9264 KB Output is correct
7 Correct 9 ms 10572 KB Output is correct
8 Correct 3 ms 460 KB Output is correct
9 Correct 4 ms 3148 KB Output is correct
10 Correct 12 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 36932 KB Output is correct
2 Correct 29 ms 37236 KB Output is correct
3 Correct 28 ms 37184 KB Output is correct
4 Correct 28 ms 37208 KB Output is correct
5 Correct 30 ms 37176 KB Output is correct
6 Correct 28 ms 33172 KB Output is correct
7 Correct 26 ms 31036 KB Output is correct
8 Correct 8 ms 1100 KB Output is correct
9 Correct 7 ms 1084 KB Output is correct
10 Correct 25 ms 30564 KB Output is correct
11 Correct 28 ms 37156 KB Output is correct
12 Correct 8 ms 4284 KB Output is correct