# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
348405 | 2021-01-15T00:12:03 Z | elizarv | 회문 (APIO14_palindrome) | C++14 | 75 ms | 63680 KB |
#include <bits/stdc++.h> using namespace std; void debug() {cout<<endl;} template<typename T,typename... Args> void debug(T a,Args... args) {cout<<a<<" ";debug(args...);} #define forn(i,a,b) for(int i=a;i<b;++i) #define SZ(x) int(x.size()) #define pb push_back #define F first #define S second #define endl "\n" typedef long long ll; typedef pair<int, int> pii; const int alfa = 26; const char L = 'a'; struct node { int next[alfa], link, len; ll cnt; node(int x, int l = 0, ll c = 1): len(x), link(l), cnt(c){ memset(next, 0, sizeof next); } int& operator[](int i) { return next[i]; } }; struct palindromic_tree { vector<node> tree; string s; int n; int last; palindromic_tree(string t = ""){ n = 0; tree.pb(node(-1)); tree.pb(node(0)); for(auto &c: t)add_char(c); } int getlink(int p){ while(s[n - tree[p].len - 1] != s[n])p = tree[p].link; return p; } void add_char(char ch){ s.pb(ch); int p = getlink(last), c = ch - L; if(!tree[p][c]){ int link = getlink(tree[p].link); link = max(1, tree[link][c]); tree[p][c] = SZ(tree); tree.pb(node(tree[p].len + 2,link, 0)); } last = tree[p][c]; tree[last].cnt++; n++; } ll getans(){ ll ans = 0; for(int i = tree.size()-1; i; i--){ ll aux = 1ll * tree[i].len * tree[i].cnt; ans = max(ans, aux); int par = tree[i].link; tree[par].cnt += tree[i].cnt; } return ans; } }; int main() { ios::sync_with_stdio(0); cin.tie(0); string s; cin >> s; palindromic_tree pt(s); cout << pt.getans() << endl; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 0 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 0 ms | 364 KB | Output is correct |
5 | Correct | 0 ms | 364 KB | Output is correct |
6 | Correct | 0 ms | 364 KB | Output is correct |
7 | Correct | 0 ms | 364 KB | Output is correct |
8 | Correct | 0 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 0 ms | 364 KB | Output is correct |
11 | Correct | 0 ms | 364 KB | Output is correct |
12 | Correct | 0 ms | 364 KB | Output is correct |
13 | Correct | 1 ms | 364 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 0 ms | 364 KB | Output is correct |
16 | Correct | 0 ms | 364 KB | Output is correct |
17 | Correct | 0 ms | 364 KB | Output is correct |
18 | Correct | 0 ms | 364 KB | Output is correct |
19 | Correct | 1 ms | 364 KB | Output is correct |
20 | Correct | 0 ms | 364 KB | Output is correct |
21 | Correct | 1 ms | 364 KB | Output is correct |
22 | Correct | 1 ms | 364 KB | Output is correct |
23 | Correct | 1 ms | 364 KB | Output is correct |
24 | Correct | 1 ms | 364 KB | Output is correct |
25 | Correct | 1 ms | 364 KB | Output is correct |
26 | Correct | 1 ms | 364 KB | Output is correct |
27 | Correct | 1 ms | 364 KB | Output is correct |
28 | Correct | 1 ms | 364 KB | Output is correct |
29 | Correct | 1 ms | 384 KB | Output is correct |
30 | Correct | 1 ms | 364 KB | Output is correct |
31 | Correct | 0 ms | 364 KB | Output is correct |
32 | Correct | 0 ms | 364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 620 KB | Output is correct |
2 | Correct | 1 ms | 620 KB | Output is correct |
3 | Correct | 1 ms | 620 KB | Output is correct |
4 | Correct | 1 ms | 620 KB | Output is correct |
5 | Correct | 1 ms | 620 KB | Output is correct |
6 | Correct | 1 ms | 620 KB | Output is correct |
7 | Correct | 1 ms | 620 KB | Output is correct |
8 | Correct | 1 ms | 620 KB | Output is correct |
9 | Correct | 1 ms | 492 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 492 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2472 KB | Output is correct |
2 | Correct | 2 ms | 2472 KB | Output is correct |
3 | Correct | 3 ms | 2472 KB | Output is correct |
4 | Correct | 2 ms | 2472 KB | Output is correct |
5 | Correct | 2 ms | 2472 KB | Output is correct |
6 | Correct | 2 ms | 2472 KB | Output is correct |
7 | Correct | 2 ms | 2472 KB | Output is correct |
8 | Correct | 1 ms | 492 KB | Output is correct |
9 | Correct | 1 ms | 492 KB | Output is correct |
10 | Correct | 2 ms | 1420 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 16104 KB | Output is correct |
2 | Correct | 19 ms | 16104 KB | Output is correct |
3 | Correct | 19 ms | 16104 KB | Output is correct |
4 | Correct | 21 ms | 16232 KB | Output is correct |
5 | Correct | 19 ms | 16104 KB | Output is correct |
6 | Correct | 17 ms | 16104 KB | Output is correct |
7 | Correct | 18 ms | 16104 KB | Output is correct |
8 | Correct | 4 ms | 876 KB | Output is correct |
9 | Correct | 9 ms | 4688 KB | Output is correct |
10 | Correct | 18 ms | 16104 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 64 ms | 63268 KB | Output is correct |
2 | Correct | 68 ms | 63560 KB | Output is correct |
3 | Correct | 66 ms | 63580 KB | Output is correct |
4 | Correct | 75 ms | 63680 KB | Output is correct |
5 | Correct | 65 ms | 63532 KB | Output is correct |
6 | Correct | 64 ms | 63532 KB | Output is correct |
7 | Correct | 45 ms | 32488 KB | Output is correct |
8 | Correct | 9 ms | 2164 KB | Output is correct |
9 | Correct | 9 ms | 2164 KB | Output is correct |
10 | Correct | 45 ms | 32488 KB | Output is correct |
11 | Correct | 65 ms | 63560 KB | Output is correct |
12 | Correct | 13 ms | 5464 KB | Output is correct |