# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
308042 | 2020-09-30T00:38:29 Z | Elephant52 | 회문 (APIO14_palindrome) | C++11 | 138 ms | 129468 KB |
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pair<int, int> > vpi; #define INF 1000000000 #define F first #define S second #define PB push_back #define MP make_pair #define rep(i,a,b) for (int i = a; i < b; i++) void setIO(string name) { freopen((name+".in").c_str(), "r", stdin); freopen((name+".out").c_str(), "w", stdout); } string s; typedef struct node { int next[26]; ll len = 0, suflink = 0, num = 0; node() {}; } node; node tree[300001]; int num, suf; vi adj[300001]; bool add_letter(int pos) { //return 1 on new palindromes int cur = suf, letter = (s[pos]-'a'), curlen = 0; while(1) { //find longest palindromic suffix of s[0...pos-1] that can include s[pos] curlen = tree[cur].len; if (pos > curlen && s[pos-1-curlen] == s[pos]) break; cur = tree[cur].suflink; } if (tree[cur].next[letter]) { //if there exists a link from smaller palindrome to s[pos] + pal + s[pos] then do nothing suf = tree[cur].next[letter]; tree[suf].num++; return 0; } //create a new palindrome with id num+1 in the tree suf = ++num; tree[num].num = 1; tree[num].len = tree[cur].len + 2; //add on s[pos] tree[cur].next[letter] = num; if (tree[num].len == 1) { tree[num].suflink = 2; //link to the empty palindrome adj[2].PB(num); return 1; } while(1) { cur = tree[cur].suflink; curlen = tree[cur].len; if (pos > curlen && s[pos-1-curlen] == s[pos]) { tree[num].suflink = tree[cur].next[letter]; adj[tree[cur].next[letter]].PB(num); break; } } return 1; } void dfs(int cur = 1, int par = -1) { for (auto edge : adj[cur]) { if (edge != par) { dfs(edge, cur); tree[cur].num += tree[edge].num; } } } void init() { num = suf = 2; tree[1].len = -1, tree[2].len = 0; tree[1].suflink = tree[2].suflink = 1; adj[1].PB(2); } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> s; init(); rep(i,0,s.length()) add_letter(i); ll ans = 0; dfs(); rep(i,1,300001) ans = max(ans, tree[i].len * tree[i].num); cout << ans << endl; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 44928 KB | Output is correct |
2 | Correct | 25 ms | 44928 KB | Output is correct |
3 | Correct | 24 ms | 44928 KB | Output is correct |
4 | Correct | 24 ms | 44928 KB | Output is correct |
5 | Correct | 24 ms | 44920 KB | Output is correct |
6 | Correct | 29 ms | 44928 KB | Output is correct |
7 | Correct | 25 ms | 44928 KB | Output is correct |
8 | Correct | 24 ms | 44920 KB | Output is correct |
9 | Correct | 25 ms | 44928 KB | Output is correct |
10 | Correct | 24 ms | 44928 KB | Output is correct |
11 | Correct | 25 ms | 44928 KB | Output is correct |
12 | Correct | 24 ms | 44928 KB | Output is correct |
13 | Correct | 24 ms | 44920 KB | Output is correct |
14 | Correct | 28 ms | 44928 KB | Output is correct |
15 | Correct | 24 ms | 44928 KB | Output is correct |
16 | Correct | 24 ms | 44928 KB | Output is correct |
17 | Correct | 24 ms | 44928 KB | Output is correct |
18 | Correct | 26 ms | 44928 KB | Output is correct |
19 | Correct | 25 ms | 44928 KB | Output is correct |
20 | Correct | 25 ms | 44928 KB | Output is correct |
21 | Correct | 24 ms | 44928 KB | Output is correct |
22 | Correct | 24 ms | 44920 KB | Output is correct |
23 | Correct | 23 ms | 44928 KB | Output is correct |
24 | Correct | 24 ms | 44920 KB | Output is correct |
25 | Correct | 26 ms | 45056 KB | Output is correct |
26 | Correct | 24 ms | 44920 KB | Output is correct |
27 | Correct | 25 ms | 44920 KB | Output is correct |
28 | Correct | 24 ms | 45056 KB | Output is correct |
29 | Correct | 24 ms | 44928 KB | Output is correct |
30 | Correct | 24 ms | 44920 KB | Output is correct |
31 | Correct | 24 ms | 44928 KB | Output is correct |
32 | Correct | 24 ms | 44928 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 45056 KB | Output is correct |
2 | Correct | 24 ms | 44928 KB | Output is correct |
3 | Correct | 24 ms | 45056 KB | Output is correct |
4 | Correct | 25 ms | 44928 KB | Output is correct |
5 | Correct | 24 ms | 45056 KB | Output is correct |
6 | Correct | 24 ms | 45056 KB | Output is correct |
7 | Correct | 24 ms | 44928 KB | Output is correct |
8 | Correct | 25 ms | 45048 KB | Output is correct |
9 | Correct | 24 ms | 44928 KB | Output is correct |
10 | Correct | 24 ms | 44920 KB | Output is correct |
11 | Correct | 24 ms | 44928 KB | Output is correct |
12 | Correct | 24 ms | 44928 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 45568 KB | Output is correct |
2 | Correct | 25 ms | 45440 KB | Output is correct |
3 | Correct | 25 ms | 45944 KB | Output is correct |
4 | Correct | 25 ms | 45824 KB | Output is correct |
5 | Correct | 25 ms | 45056 KB | Output is correct |
6 | Correct | 25 ms | 45184 KB | Output is correct |
7 | Correct | 26 ms | 45440 KB | Output is correct |
8 | Correct | 25 ms | 44920 KB | Output is correct |
9 | Correct | 24 ms | 44928 KB | Output is correct |
10 | Correct | 26 ms | 45176 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 37 ms | 51324 KB | Output is correct |
2 | Correct | 37 ms | 49912 KB | Output is correct |
3 | Correct | 39 ms | 54392 KB | Output is correct |
4 | Correct | 40 ms | 52216 KB | Output is correct |
5 | Correct | 38 ms | 46208 KB | Output is correct |
6 | Correct | 33 ms | 47224 KB | Output is correct |
7 | Correct | 34 ms | 48376 KB | Output is correct |
8 | Correct | 26 ms | 45184 KB | Output is correct |
9 | Correct | 28 ms | 47096 KB | Output is correct |
10 | Correct | 35 ms | 45944 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 138 ms | 129468 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |