답안 #248560

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
248560 2020-07-12T18:09:32 Z wzy 회문 (APIO14_palindrome) C++11
100 / 100
56 ms 45588 KB
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <climits>

using namespace std;

#define F first
#define S second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x) , end(x)
#define sz(x) (int)(x).size()
#define pb push_back

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<pll> vpl;
typedef vector<int> vi;

ll modpow(ll b, ll e ,ll mod){
	ll ans = 1;
	for (; e; b = b * b % mod, e /= 2)
		if (e & 1) ans = ans * b % mod;
	return ans;
}
const int N = 300005;
string s;
int bigsuf = -1 , id = 2;
struct node{
	int link , len , occ;
	vi go;
} tree[N];

void init(){
	bigsuf = 2;
	id = 2;
	tree[1].len = -1 , tree[1].link = 1, tree[1].go = vi(26,0) , tree[1].occ = 0;
	tree[2].len = 0 , tree[2].link = 1 , tree[2].go = vi(26,0) , tree[2].occ = 0;
}

void append(int p){
	int cur = bigsuf , c = s[p] - 'a';
	while((p-1-tree[cur].len < 0) || s[p - 1 - tree[cur].len] != s[p])
		cur = tree[cur].link;
	if(!tree[cur].go[c]){
		int link = tree[cur].link;
		while((p-1-tree[link].len < 0) || s[p - 1 - tree[link].len] != s[p])
			link = tree[link].link;		
		tree[cur].go[c] = ++id;
		tree[id].go = vi(26,0);
		tree[id].len = tree[cur].len + 2;
		tree[id].link = (tree[id].len == 1 ? 2 : tree[link].go[c]);
	}
	bigsuf = tree[cur].go[c];
	tree[bigsuf].occ ++ ;
}

int32_t main(){
	int t = 1; 
	for(int ii = 0 ; ii < t ; ii ++){
		cin >> s;
		init();
		for(int i = 0 ; i < sz(s) ; i++){
			append(i);
		}
		ll ans = 0;
		for(int i = id ; i > 2 ; i --){
			tree[tree[i].link].occ += tree[i].occ;
			ans = max(ans , (tree[i].occ * 1ll) * (tree[i].len*1ll)) ; 
		}
		cout << ans << endl;
	}
}

/* clever stuff:
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and STAY ORGANIZED
	* Keep it simple stupid
	* WRITE STUFF DOWN
	* math -> gcd / lcm / divisors? 
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 12032 KB Output is correct
2 Correct 6 ms 12032 KB Output is correct
3 Correct 6 ms 12032 KB Output is correct
4 Correct 8 ms 12032 KB Output is correct
5 Correct 6 ms 12032 KB Output is correct
6 Correct 6 ms 12032 KB Output is correct
7 Correct 6 ms 12032 KB Output is correct
8 Correct 7 ms 12032 KB Output is correct
9 Correct 6 ms 12032 KB Output is correct
10 Correct 6 ms 12032 KB Output is correct
11 Correct 7 ms 12032 KB Output is correct
12 Correct 6 ms 12032 KB Output is correct
13 Correct 6 ms 12032 KB Output is correct
14 Correct 6 ms 12032 KB Output is correct
15 Correct 6 ms 12032 KB Output is correct
16 Correct 6 ms 12032 KB Output is correct
17 Correct 6 ms 12032 KB Output is correct
18 Correct 6 ms 12032 KB Output is correct
19 Correct 6 ms 12032 KB Output is correct
20 Correct 7 ms 12032 KB Output is correct
21 Correct 6 ms 12032 KB Output is correct
22 Correct 7 ms 12032 KB Output is correct
23 Correct 6 ms 12032 KB Output is correct
24 Correct 7 ms 12032 KB Output is correct
25 Correct 6 ms 12032 KB Output is correct
26 Correct 6 ms 12032 KB Output is correct
27 Correct 6 ms 12032 KB Output is correct
28 Correct 7 ms 12032 KB Output is correct
29 Correct 6 ms 12032 KB Output is correct
30 Correct 6 ms 12032 KB Output is correct
31 Correct 6 ms 12032 KB Output is correct
32 Correct 7 ms 12032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 12160 KB Output is correct
2 Correct 6 ms 12160 KB Output is correct
3 Correct 6 ms 12160 KB Output is correct
4 Correct 7 ms 12160 KB Output is correct
5 Correct 6 ms 12160 KB Output is correct
6 Correct 7 ms 12160 KB Output is correct
7 Correct 6 ms 12160 KB Output is correct
8 Correct 6 ms 12160 KB Output is correct
9 Correct 7 ms 12160 KB Output is correct
10 Correct 9 ms 12032 KB Output is correct
11 Correct 6 ms 12032 KB Output is correct
12 Correct 6 ms 12160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 13184 KB Output is correct
2 Correct 7 ms 13184 KB Output is correct
3 Correct 8 ms 13184 KB Output is correct
4 Correct 8 ms 13184 KB Output is correct
5 Correct 9 ms 13184 KB Output is correct
6 Correct 8 ms 13184 KB Output is correct
7 Correct 9 ms 13184 KB Output is correct
8 Correct 7 ms 12160 KB Output is correct
9 Correct 7 ms 12160 KB Output is correct
10 Correct 8 ms 12800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 23168 KB Output is correct
2 Correct 23 ms 23168 KB Output is correct
3 Correct 23 ms 23040 KB Output is correct
4 Correct 23 ms 23160 KB Output is correct
5 Correct 23 ms 23168 KB Output is correct
6 Correct 20 ms 20096 KB Output is correct
7 Correct 21 ms 21376 KB Output is correct
8 Correct 13 ms 12416 KB Output is correct
9 Correct 15 ms 14716 KB Output is correct
10 Correct 21 ms 21376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 45204 KB Output is correct
2 Correct 56 ms 45556 KB Output is correct
3 Correct 53 ms 45588 KB Output is correct
4 Correct 53 ms 45588 KB Output is correct
5 Correct 53 ms 45588 KB Output is correct
6 Correct 50 ms 41876 KB Output is correct
7 Correct 50 ms 39956 KB Output is correct
8 Correct 26 ms 12944 KB Output is correct
9 Correct 26 ms 12944 KB Output is correct
10 Correct 47 ms 39572 KB Output is correct
11 Correct 52 ms 45588 KB Output is correct
12 Correct 29 ms 15764 KB Output is correct