Submission #682037

# Submission time Handle Problem Language Result Execution time Memory
682037 2023-01-15T10:47:13 Z _skb_ Palindromes (APIO14_palindrome) C++17
100 / 100
25 ms 34920 KB
#include<bits/stdc++.h>
using namespace std;

using i64 = long long;
using u64 = unsigned long long;

struct debug {
#define contPrint { *this << "["; \
        int f = 0; for(auto it : x) { *this << (f?", ":""); *this << it; f = 1;} \
        *this << "]"; return *this;}
 
    ~debug(){cerr << endl;}
    template<class c> debug& operator<<(c x) {cerr << x; return *this;}
    template<class c, class d>
    debug& operator<<(pair<c, d> x) {*this << "(" << x.first << ", " << x.second << ")"; 
        return *this;}
    template<class c> debug& operator<<(vector<c> x) contPrint;
#undef contPrint
};

#define dbg(x) "[" << #x << ": " << x << "]  "
#define Wa() cerr << "[LINE: " << __LINE__ << "] -> "; debug() << 
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);

const int N = 3e5 + 5;
int tree[N][26], idx;
int len[N], lnk[N], t;
char ch[N];

void init()
{
    len[1] = -1, lnk[1] = 1;
    len[2] = 0, lnk[2] = 1;
    idx = t = 2;
}

int cnt[N];
i64 ans = 0;

void extend(int p)
{
    while(ch[p - len[t] - 1] != ch[p]) t = lnk[t];
    int x = lnk[t], c = ch[p] - 'a';
    while(ch[p - len[x] - 1] != ch[p]) x = lnk[x];
    if(!tree[t][c]) {
        tree[t][c] = ++idx;
        len[idx] = len[t] + 2;
        lnk[idx] = len[idx] == 1 ? 2 : tree[x][c];
    }
    t = tree[t][c];
    cnt[t]++;
}

int main() 
{
    init();
    scanf("%s", ch + 1);
    for(int i = 1; ch[i]; i++) {
        extend(i);
    }
    for(int i = idx; i > 2; i--) {
        cnt[lnk[i]] += cnt[i];
    }
    for(int i = 3; i <= idx; i++) {
        ans = max(ans, 1LL * len[i] * cnt[i]);
    }
    printf("%lld\n", ans);
}

Compilation message

palindrome.cpp: In function 'int main()':
palindrome.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |     scanf("%s", ch + 1);
      |     ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 328 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 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 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1364 KB Output is correct
2 Correct 1 ms 1364 KB Output is correct
3 Correct 2 ms 1364 KB Output is correct
4 Correct 1 ms 1364 KB Output is correct
5 Correct 2 ms 1364 KB Output is correct
6 Correct 1 ms 1364 KB Output is correct
7 Correct 1 ms 1364 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
# Verdict Execution time Memory Grader output
1 Correct 10 ms 11732 KB Output is correct
2 Correct 8 ms 11732 KB Output is correct
3 Correct 8 ms 11732 KB Output is correct
4 Correct 9 ms 11732 KB Output is correct
5 Correct 8 ms 11732 KB Output is correct
6 Correct 6 ms 8660 KB Output is correct
7 Correct 7 ms 10072 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 4 ms 3164 KB Output is correct
10 Correct 8 ms 10068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 34576 KB Output is correct
2 Correct 24 ms 34508 KB Output is correct
3 Correct 24 ms 34868 KB Output is correct
4 Correct 24 ms 34900 KB Output is correct
5 Correct 25 ms 34920 KB Output is correct
6 Correct 22 ms 31060 KB Output is correct
7 Correct 21 ms 29084 KB Output is correct
8 Correct 6 ms 980 KB Output is correct
9 Correct 6 ms 980 KB Output is correct
10 Correct 21 ms 28636 KB Output is correct
11 Correct 25 ms 34892 KB Output is correct
12 Correct 7 ms 4072 KB Output is correct