답안 #248609

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
248609 2020-07-12T21:18:27 Z wzy 회문 (APIO14_palindrome) C++11
100 / 100
56 ms 45332 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;
int bigsuf , id;
struct node{
	int link , len , oc = 0;
	vi go;
} tree[N];

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

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


int32_t main(){
	cin >> s;
	init();
	rep(i,0,sz(s)) append(i);
	ll ans = 0;
	for(int j = id ;j > 2 ; j --){
		tree[tree[j].link].oc += tree[j].oc;
		ans = max(ans , ((1ll * tree[j].len)) * ((1ll * tree[j].oc)));
	}	
	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 6 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 6 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 6 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 7 ms 12032 KB Output is correct
16 Correct 7 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 7 ms 12032 KB Output is correct
20 Correct 6 ms 12032 KB Output is correct
21 Correct 6 ms 12032 KB Output is correct
22 Correct 6 ms 12032 KB Output is correct
23 Correct 6 ms 12032 KB Output is correct
24 Correct 6 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 6 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 6 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 6 ms 12160 KB Output is correct
5 Correct 7 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 7 ms 12160 KB Output is correct
9 Correct 6 ms 12160 KB Output is correct
10 Correct 6 ms 12032 KB Output is correct
11 Correct 6 ms 12032 KB Output is correct
12 Correct 7 ms 12160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 13184 KB Output is correct
2 Correct 8 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 8 ms 13184 KB Output is correct
6 Correct 8 ms 13184 KB Output is correct
7 Correct 8 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 7 ms 12800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 23040 KB Output is correct
2 Correct 22 ms 23160 KB Output is correct
3 Correct 22 ms 23168 KB Output is correct
4 Correct 22 ms 23168 KB Output is correct
5 Correct 22 ms 23168 KB Output is correct
6 Correct 19 ms 20096 KB Output is correct
7 Correct 21 ms 21376 KB Output is correct
8 Correct 13 ms 12288 KB Output is correct
9 Correct 15 ms 14720 KB Output is correct
10 Correct 20 ms 21376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 45204 KB Output is correct
2 Correct 56 ms 45264 KB Output is correct
3 Correct 54 ms 45212 KB Output is correct
4 Correct 53 ms 45204 KB Output is correct
5 Correct 54 ms 45332 KB Output is correct
6 Correct 52 ms 41492 KB Output is correct
7 Correct 49 ms 39700 KB Output is correct
8 Correct 26 ms 12688 KB Output is correct
9 Correct 26 ms 12688 KB Output is correct
10 Correct 48 ms 39188 KB Output is correct
11 Correct 53 ms 45204 KB Output is correct
12 Correct 28 ms 15516 KB Output is correct