Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- #define SZ(X) ((int)(X).size())
- int modmul(int A, int B, int mod)
- {
- return (A*B-(int)((long double)A*B/mod)*mod+mod)%mod;
- }
- class Strhash{
- private:
- vector<long long> hash, pows;
- const long long mod = 304250263527209;
- public:
- Strhash(string s, int prm=0xdefaced){
- hash.emplace_back(0);
- pows.emplace_back(1);
- for(unsigned i = 0; i < s.size(); ++i){
- hash.emplace_back((hash.back()*prm+s[i])%mod);
- pows.emplace_back(pows.back()*prm%mod);
- }
- }
- Strhash(char *c, int prm=0xdefaced){
- hash.emplace_back(0);
- pows.emplace_back(1);
- for(int i = 0; c[i] != '\0'; ++i){
- hash.emplace_back((hash.back()*prm+c[i])%mod);
- pows.emplace_back(pows.back()*prm%mod);
- }
- }
- long long gethash(int l, int r){//[l,r)
- return (hash[r]+mod-modmul(hash[l], pows[r-l], mod))%mod;
- }
- };
- int same[200000];
- int32_t main(){
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int small=1, big;
- string s;
- cin >> big >> s;
- Strhash tool(s, 10079);
- while(big >= small){
- int cnt = 0;
- int mid = (big + small) / 2;
- for(int i = 0; i+mid <= SZ(s); ++i){
- same[cnt++] = tool.gethash(i, i+mid);
- }
- sort(same, same+cnt);
- if(unique(same, same+cnt)-same == cnt){
- big = mid - 1;
- }else{
- small = mid + 1;
- }
- //cout << SZ(same ) << ' ' << mid << '\n';
- }
- cout << big << '\n';
- return 0;
- }
RAW Paste Data