Submission #91511

# Submission time Handle Problem Language Result Execution time Memory
91511 2018-12-28T02:09:42 Z RezwanArefin01 Palindromes (APIO14_palindrome) C++17
100 / 100
56 ms 39952 KB
///usr/bin/g++ -O2 $0 -o ${0%.cpp} && echo "----------" && ./${0%.cpp}; exit;
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii; 

const int N = 3e5 + 10; 

int t[N][26], len[N], link[N], occ[N], idx, suff; 
char s[N]; int n; 

bool extend(int pos) {
    int cur = suff, c = s[pos] - 'a';
    int cnt = 0; 
    while(pos - len[cur] - 1 < 0 || s[pos - len[cur] - 1] != s[pos]) 
        cur = link[cur]; 
    if(t[cur][c]) {
        suff = t[cur][c]; 
        occ[t[cur][c]]++;
        return 0; 
    }
    suff = ++idx; 
    t[cur][c] = idx; 
    len[idx] = len[cur] + 2;    
    occ[idx] = 1; 
    if(len[idx] == 1) {
        link[idx] = 2; 
        return 1;
    }
    cur = link[cur];
    while(pos - len[cur] - 1 < 0 || s[pos - len[cur] - 1] != s[pos]) 
        cur = link[cur]; 
    link[idx] = t[cur][c]; 
    return 1; 
}

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

int main(int argc, char const *argv[]) {
	scanf("%s", s); n = strlen(s); 

    init(); 
    for(int i = 0; i < n; i++) 
        extend(i); 

    ll ans = 0; 
    for(int i = idx; i >= 3; i--)  {
        occ[link[i]] += occ[i]; 
        ans = max(ans, (ll) len[i] * occ[i]); 
    }
    printf("%lld\n", ans); 
}

Compilation message

palindrome.cpp: In function 'bool extend(int)':
palindrome.cpp:15:9: warning: unused variable 'cnt' [-Wunused-variable]
     int cnt = 0; 
         ^~~
palindrome.cpp: In function 'int main(int, const char**)':
palindrome.cpp:45:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", s); n = strlen(s); 
  ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 524 KB Output is correct
5 Correct 2 ms 528 KB Output is correct
6 Correct 2 ms 532 KB Output is correct
7 Correct 2 ms 536 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 2 ms 644 KB Output is correct
12 Correct 2 ms 780 KB Output is correct
13 Correct 2 ms 780 KB Output is correct
14 Correct 2 ms 780 KB Output is correct
15 Correct 2 ms 780 KB Output is correct
16 Correct 2 ms 780 KB Output is correct
17 Correct 2 ms 780 KB Output is correct
18 Correct 2 ms 804 KB Output is correct
19 Correct 2 ms 808 KB Output is correct
20 Correct 2 ms 812 KB Output is correct
21 Correct 2 ms 816 KB Output is correct
22 Correct 2 ms 820 KB Output is correct
23 Correct 2 ms 824 KB Output is correct
24 Correct 2 ms 828 KB Output is correct
25 Correct 2 ms 832 KB Output is correct
26 Correct 2 ms 836 KB Output is correct
27 Correct 2 ms 836 KB Output is correct
28 Correct 2 ms 844 KB Output is correct
29 Correct 2 ms 848 KB Output is correct
30 Correct 2 ms 852 KB Output is correct
31 Correct 2 ms 856 KB Output is correct
32 Correct 2 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1112 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
3 Correct 2 ms 1124 KB Output is correct
4 Correct 2 ms 1124 KB Output is correct
5 Correct 2 ms 1128 KB Output is correct
6 Correct 2 ms 1132 KB Output is correct
7 Correct 2 ms 1136 KB Output is correct
8 Correct 2 ms 1140 KB Output is correct
9 Correct 2 ms 1140 KB Output is correct
10 Correct 2 ms 1140 KB Output is correct
11 Correct 2 ms 1140 KB Output is correct
12 Correct 2 ms 1140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2312 KB Output is correct
2 Correct 3 ms 2312 KB Output is correct
3 Correct 3 ms 2332 KB Output is correct
4 Correct 3 ms 2348 KB Output is correct
5 Correct 3 ms 2376 KB Output is correct
6 Correct 3 ms 2404 KB Output is correct
7 Correct 3 ms 2432 KB Output is correct
8 Correct 2 ms 2432 KB Output is correct
9 Correct 2 ms 2432 KB Output is correct
10 Correct 3 ms 2432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 12848 KB Output is correct
2 Correct 16 ms 12920 KB Output is correct
3 Correct 16 ms 13056 KB Output is correct
4 Correct 16 ms 13148 KB Output is correct
5 Correct 17 ms 13248 KB Output is correct
6 Correct 12 ms 13248 KB Output is correct
7 Correct 13 ms 13248 KB Output is correct
8 Correct 4 ms 13248 KB Output is correct
9 Correct 6 ms 13248 KB Output is correct
10 Correct 15 ms 13248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 37016 KB Output is correct
2 Correct 41 ms 37296 KB Output is correct
3 Correct 41 ms 37592 KB Output is correct
4 Correct 42 ms 37888 KB Output is correct
5 Correct 56 ms 38188 KB Output is correct
6 Correct 42 ms 38188 KB Output is correct
7 Correct 40 ms 38188 KB Output is correct
8 Correct 6 ms 38188 KB Output is correct
9 Correct 7 ms 38188 KB Output is correct
10 Correct 44 ms 38188 KB Output is correct
11 Correct 43 ms 39952 KB Output is correct
12 Correct 10 ms 39952 KB Output is correct