-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSAM.cpp
More file actions
53 lines (38 loc) · 866 Bytes
/
Copy pathSAM.cpp
File metadata and controls
53 lines (38 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "../../headers/SAM.h"
#include <algorithm>
#include <functional>
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s;
cin >> s;
CPTH::SAM<char> sam('a');
assert(sam.size() == 2);
sam.clear();
assert(sam.size() == 1);
vector<int> cnt(s.size() * 2 + 10, 0);
for (auto x : s)
cnt[sam.append(x)] = 1;
sam = CPTH::SAM<>(s);
sam.buildTree();
long long ans = 0;
function<void(int)> dfs = [&](int u) {
assert(sam[u]['.'] == 0);
for (auto v : sam.children(u))
{
dfs(v);
cnt[u] += cnt[v];
}
if (cnt[u] > 1)
ans = max(ans, (long long)sam[u].len * cnt[u]);
};
dfs(0);
int u = 0;
for (auto x : s)
u = sam[u][x];
assert(cnt[u] == 1);
cout << ans;
return 0;
}