답안 #307946

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
307946 2020-09-29T15:54:23 Z tushar_2658 회문 (APIO14_palindrome) C++14
100 / 100
32 ms 36064 KB
#include "bits/stdc++.h"
using namespace std;

const int maxn = 600005;
using ll = long long;

int t[maxn][26], link[maxn], len[maxn];
int node, cur;
ll dp[maxn];
string s;

void init(){
  len[1] = -1;
  len[2] = 0;
  link[1] = 1;
  link[2] = 1;
  node = cur = 2;
}

void extend(int idx){
  while(s[idx - len[cur] - 1] != s[idx]){
    cur = link[cur];
  }
  int x = link[cur];
  while(s[idx - len[x] - 1] != s[idx]){
    x = link[x];
  }
  int c = s[idx] - 'a';
  if(!t[cur][c]){
    t[cur][c] = ++node;
    len[node] = len[cur] + 2;
    if(len[node] == 1){
      link[node] = 2;
    }else {
      link[node] = t[x][c];
    }
  }
  cur = t[cur][c];
  dp[cur]++;
}

int main(int argc, char const *argv[])
{
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> s;
  s = "#" + s;
  init();
  int n = s.size();
  for(int i = 1; i < n; ++i){
    extend(i);
  }
  ll ans = 0;
  for(int i = node; i > 2; --i){
    dp[link[i]] += dp[i];
  }
  for(int i = node; i > 2; --i){
    ans = max(ans, len[i] * 1LL * dp[i]);
  }
  cout << ans << endl;

  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 416 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1536 KB Output is correct
2 Correct 2 ms 1536 KB Output is correct
3 Correct 1 ms 1536 KB Output is correct
4 Correct 2 ms 1536 KB Output is correct
5 Correct 2 ms 1536 KB Output is correct
6 Correct 1 ms 1536 KB Output is correct
7 Correct 2 ms 1536 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 12284 KB Output is correct
2 Correct 11 ms 12284 KB Output is correct
3 Correct 11 ms 12284 KB Output is correct
4 Correct 11 ms 12412 KB Output is correct
5 Correct 11 ms 12284 KB Output is correct
6 Correct 8 ms 9084 KB Output is correct
7 Correct 9 ms 10492 KB Output is correct
8 Correct 3 ms 636 KB Output is correct
9 Correct 4 ms 3324 KB Output is correct
10 Correct 10 ms 10492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 36052 KB Output is correct
2 Correct 31 ms 36056 KB Output is correct
3 Correct 31 ms 36052 KB Output is correct
4 Correct 32 ms 36056 KB Output is correct
5 Correct 32 ms 36064 KB Output is correct
6 Correct 29 ms 32132 KB Output is correct
7 Correct 27 ms 30048 KB Output is correct
8 Correct 6 ms 1032 KB Output is correct
9 Correct 6 ms 1032 KB Output is correct
10 Correct 29 ms 29664 KB Output is correct
11 Correct 30 ms 36064 KB Output is correct
12 Correct 10 ms 4192 KB Output is correct