Submission #570129

# Submission time Handle Problem Language Result Execution time Memory
570129 2022-05-28T17:02:06 Z _Bohemian Palindromes (APIO14_palindrome) C++17
47 / 100
1000 ms 33024 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> PII;
const ll mx = 3e5+10;

const int A = 26;
const int N = 300010;

char s[N]; // 1-Indexed

int last, ptr, nxt[N][A], link[N], len[N], occ[N], depth[N], end_At[N];

void feed(int At) {
    while(s[At-len[last]-1]!=s[At])
        last = link[last];

    int ch = s[At]-'a', temp = link[last];

    while(s[At-len[temp]-1]!=s[At])
        temp = link[temp];

    if(!nxt[last][ch]) {
        nxt[last][ch] = ++ptr, len[ptr] = len[last]+2;
        link[ptr] = len[ptr]==1?2:nxt[temp][ch];
        depth[ptr] = depth[link[ptr]] + 1;
    }
    last = nxt[last][ch], ++occ[last];
    end_At[At] = depth[last];
}

int main() {

    int t = 1;
    while(t--) {
        len[1] = -1, link[1] = 1, len[2] = 0, link[2] = 1;
        ptr = last = 2;
        int n;
        scanf("%s", s + 1);
        for(int i=1; n = strlen(s+1), i<=n; i++) {
            feed(i);
        }
        for(int i = ptr; i > 2; i--) occ[link[i]] += occ[i];

        ll Ans = 0;
        for(int i=1; i<=ptr; i++) {
            ll p = len[i] * occ[i];
            Ans = max(Ans,p);
        }
        cout<<Ans<<endl;
    }
}

Compilation message

palindrome.cpp: In function 'int main()':
palindrome.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         scanf("%s", s + 1);
      |         ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 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 332 KB Output is correct
5 Correct 1 ms 340 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 1 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 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 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 324 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 328 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 340 KB Output is correct
27 Correct 1 ms 324 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 328 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 468 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 340 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1492 KB Output is correct
2 Correct 3 ms 1492 KB Output is correct
3 Correct 3 ms 1492 KB Output is correct
4 Correct 3 ms 1484 KB Output is correct
5 Correct 3 ms 1488 KB Output is correct
6 Correct 3 ms 1492 KB Output is correct
7 Correct 3 ms 1488 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 3 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 142 ms 12580 KB Output is correct
2 Correct 140 ms 12560 KB Output is correct
3 Incorrect 143 ms 12628 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1092 ms 33024 KB Time limit exceeded
2 Halted 0 ms 0 KB -