Submission #725269

# Submission time Handle Problem Language Result Execution time Memory
725269 2023-04-17T06:10:03 Z quiet_space Palindromes (APIO14_palindrome) C++14
100 / 100
63 ms 65496 KB
#include <bits/stdc++.h>
#define FOR(i,j,k) for(int i=j; i<=k; ++i)
#define ROF(i,j,k) for(int i=j; i>=k; --i)
inline int read (void) {
  int x = 0, f = 1, ch = getchar();
  while(!isdigit(ch)) { if(ch == '-') f = -f; ch = getchar(); }
  while(isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); }
  return x * f;
}
using ll = long long;
const int maxn = 300005;
char c[maxn];
int tot, lst, trans[maxn][26], len[maxn], fail[maxn], cnt[maxn];
inline int newnode (int l) {
  len[++ tot] = l; return tot;
}
inline void prework (void) {
  tot = -1; fail[0] = 1;
  newnode (0); newnode (-1);
}
inline int getfail (int x, int pos) {
  while(c[pos] != c[pos - len[x] - 1]) x = fail[x];
  return x;
}
inline void insert (int pos) {
  int x = getfail (lst, pos);
  if(!trans[x][c[pos] - 'a']) {
    int y = newnode (len[x] + 2);
    fail[y] = trans[getfail (fail[x], pos)][c[pos] - 'a'];
    trans[x][c[pos] - 'a'] = y;
  } lst = trans[x][c[pos] - 'a'];
}
std::vector <int> v[maxn];
ll ans;
void dfs (int x) {
  for(auto&it:v[x]) {
    dfs (it);
    cnt[x] += cnt[it];
  }
  if(len[x] > 0) ans = std::max(ans, 1ll * len[x] * cnt[x]);
}
int main (void) {
  scanf("%s", c+1);
  int n = strlen(c+1);
  prework ();
  FOR(i,1,n) {
    insert (i);
    ++ cnt[lst];
  }
  FOR(i,2,tot) v[fail[i]].push_back(i);
  dfs (0); dfs (1);
  printf("%lld\n", ans);
  return 0;
}

Compilation message

palindrome.cpp: In function 'int main()':
palindrome.cpp:43:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |   scanf("%s", c+1);
      |   ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 5 ms 7360 KB Output is correct
5 Correct 7 ms 7356 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7356 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 4 ms 7276 KB Output is correct
12 Correct 4 ms 7356 KB Output is correct
13 Correct 4 ms 7360 KB Output is correct
14 Correct 4 ms 7380 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 5 ms 7380 KB Output is correct
17 Correct 5 ms 7356 KB Output is correct
18 Correct 5 ms 7388 KB Output is correct
19 Correct 4 ms 7380 KB Output is correct
20 Correct 4 ms 7380 KB Output is correct
21 Correct 5 ms 7380 KB Output is correct
22 Correct 5 ms 7380 KB Output is correct
23 Correct 5 ms 7312 KB Output is correct
24 Correct 4 ms 7380 KB Output is correct
25 Correct 6 ms 7380 KB Output is correct
26 Correct 4 ms 7380 KB Output is correct
27 Correct 4 ms 7364 KB Output is correct
28 Correct 4 ms 7380 KB Output is correct
29 Correct 4 ms 7364 KB Output is correct
30 Correct 5 ms 7380 KB Output is correct
31 Correct 4 ms 7356 KB Output is correct
32 Correct 4 ms 7364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7508 KB Output is correct
2 Correct 4 ms 7508 KB Output is correct
3 Correct 4 ms 7492 KB Output is correct
4 Correct 5 ms 7484 KB Output is correct
5 Correct 5 ms 7484 KB Output is correct
6 Correct 5 ms 7480 KB Output is correct
7 Correct 5 ms 7508 KB Output is correct
8 Correct 4 ms 7492 KB Output is correct
9 Correct 4 ms 7484 KB Output is correct
10 Correct 4 ms 7364 KB Output is correct
11 Correct 4 ms 7380 KB Output is correct
12 Correct 5 ms 7356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9044 KB Output is correct
2 Correct 5 ms 8916 KB Output is correct
3 Correct 6 ms 9300 KB Output is correct
4 Correct 7 ms 9160 KB Output is correct
5 Correct 5 ms 8660 KB Output is correct
6 Correct 5 ms 8660 KB Output is correct
7 Correct 5 ms 8916 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7364 KB Output is correct
10 Correct 6 ms 8148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 24448 KB Output is correct
2 Correct 17 ms 23252 KB Output is correct
3 Correct 19 ms 26708 KB Output is correct
4 Correct 18 ms 25008 KB Output is correct
5 Correct 17 ms 20052 KB Output is correct
6 Correct 14 ms 17688 KB Output is correct
7 Correct 19 ms 20084 KB Output is correct
8 Correct 6 ms 7604 KB Output is correct
9 Correct 10 ms 11988 KB Output is correct
10 Correct 15 ms 18132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 58300 KB Output is correct
2 Correct 42 ms 53292 KB Output is correct
3 Correct 53 ms 65496 KB Output is correct
4 Correct 46 ms 56472 KB Output is correct
5 Correct 63 ms 46384 KB Output is correct
6 Correct 42 ms 48204 KB Output is correct
7 Correct 38 ms 44732 KB Output is correct
8 Correct 10 ms 8020 KB Output is correct
9 Correct 10 ms 8020 KB Output is correct
10 Correct 47 ms 39388 KB Output is correct
11 Correct 48 ms 53708 KB Output is correct
12 Correct 13 ms 13268 KB Output is correct