結果

問題 No.2606 Mirror Relay
ユーザー 沙耶花沙耶花
提出日時 2024-01-12 23:15:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 461 ms / 2,000 ms
コード長 3,678 bytes
コンパイル時間 4,797 ms
コンパイル使用メモリ 281,424 KB
実行使用メモリ 32,252 KB
最終ジャッジ日時 2024-01-12 23:15:48
合計ジャッジ時間 13,344 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 3 ms
6,676 KB
testcase_05 AC 3 ms
6,676 KB
testcase_06 AC 4 ms
6,676 KB
testcase_07 AC 3 ms
6,676 KB
testcase_08 AC 3 ms
6,676 KB
testcase_09 AC 3 ms
6,676 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 4 ms
6,676 KB
testcase_12 AC 4 ms
6,676 KB
testcase_13 AC 3 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 4 ms
6,676 KB
testcase_20 AC 4 ms
6,676 KB
testcase_21 AC 4 ms
6,676 KB
testcase_22 AC 4 ms
6,676 KB
testcase_23 AC 4 ms
6,676 KB
testcase_24 AC 4 ms
6,676 KB
testcase_25 AC 4 ms
6,676 KB
testcase_26 AC 4 ms
6,676 KB
testcase_27 AC 5 ms
6,676 KB
testcase_28 AC 4 ms
6,676 KB
testcase_29 AC 4 ms
6,676 KB
testcase_30 AC 4 ms
6,676 KB
testcase_31 AC 4 ms
6,676 KB
testcase_32 AC 4 ms
6,676 KB
testcase_33 AC 4 ms
6,676 KB
testcase_34 AC 4 ms
6,676 KB
testcase_35 AC 3 ms
6,676 KB
testcase_36 AC 4 ms
6,676 KB
testcase_37 AC 4 ms
6,676 KB
testcase_38 AC 4 ms
6,676 KB
testcase_39 AC 141 ms
16,360 KB
testcase_40 AC 141 ms
16,352 KB
testcase_41 AC 147 ms
16,356 KB
testcase_42 AC 143 ms
16,368 KB
testcase_43 AC 143 ms
16,364 KB
testcase_44 AC 160 ms
16,352 KB
testcase_45 AC 142 ms
16,356 KB
testcase_46 AC 142 ms
16,364 KB
testcase_47 AC 142 ms
16,356 KB
testcase_48 AC 143 ms
16,352 KB
testcase_49 AC 238 ms
19,860 KB
testcase_50 AC 222 ms
20,292 KB
testcase_51 AC 233 ms
20,520 KB
testcase_52 AC 238 ms
21,196 KB
testcase_53 AC 246 ms
22,628 KB
testcase_54 AC 241 ms
20,088 KB
testcase_55 AC 226 ms
26,708 KB
testcase_56 AC 218 ms
20,088 KB
testcase_57 AC 246 ms
21,340 KB
testcase_58 AC 235 ms
21,256 KB
testcase_59 AC 206 ms
17,988 KB
testcase_60 AC 204 ms
17,976 KB
testcase_61 AC 200 ms
17,948 KB
testcase_62 AC 201 ms
17,952 KB
testcase_63 AC 209 ms
18,048 KB
testcase_64 AC 208 ms
17,956 KB
testcase_65 AC 206 ms
17,984 KB
testcase_66 AC 201 ms
17,944 KB
testcase_67 AC 203 ms
17,952 KB
testcase_68 AC 201 ms
17,964 KB
testcase_69 AC 461 ms
32,252 KB
testcase_70 AC 2 ms
6,676 KB
testcase_71 AC 2 ms
6,676 KB
testcase_72 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001

int op(int a,int b){
	return min(a,b);
}
int e(){
	return Inf32;
}
int X = 0;
bool f(int x){
	return x >= X;
}
struct rolling_hash{

	long long t_hash;
	static inline vector<long long> power;
	static const long long MOD = (1LL<<61)-1;
	static const long long b = 123456;
	int sz;
	
	rolling_hash(){		
		sz = 0;
		t_hash = 0;
	}
	
	rolling_hash(char c){
		sz = 1;
		t_hash = b*c;
	}

	long long mul(__int128 x,__int128 y){
		__int128 t = x*y;
		t = (t>>61) + (t&MOD);
		
		if(t>=MOD)t -= MOD;
		return t;
	}
	
	long long get_pow(int sz){
		if(power.size()>sz)return power[sz];
		
		while(power.size()<=sz){
			if(power.size()==0)power.push_back(1);
			else power.push_back(mul(power.back(),b));
		}
		return power.back();
		
	}
	
	rolling_hash &operator+=(const rolling_hash &another){
		
		(*this).t_hash = mul((*this).t_hash,get_pow(another.sz));
		(*this).t_hash += another.t_hash;
		if((*this).t_hash>=MOD)(*this).t_hash -= MOD;
			
		(*this).sz += another.sz;
		
		return (*this);
	}
	
	rolling_hash operator+(const rolling_hash &another)const{
		return (rolling_hash(*this)+=another);
	}
	
	rolling_hash &operator-=(const rolling_hash &another){

		(*this).t_hash += MOD - mul(another.t_hash,get_pow((*this).sz-another.sz));
		if((*this).t_hash>=MOD)(*this).t_hash -= MOD;
			
		(*this).sz -= another.sz;

		return (*this);
	}
	
	rolling_hash operator-(const rolling_hash &another)const{
		return (rolling_hash(*this)-=another);
	}
	
	bool operator<(const rolling_hash &another)const{
		if((*this).t_hash!=another.t_hash)return (*this).t_hash<another.t_hash;
		return (*this).sz<another.sz;
	}
	
	bool operator==(const rolling_hash &another)const{
		return ((*this).t_hash==another.t_hash && (*this).sz==another.sz);
	}

	
};

int main(){
	
	string s;
	cin>>s;
	int n = s.size();
	vector<rolling_hash> R(n+1),rR(n+1);
	rep(i,n){
		R[i+1] = R[i] + rolling_hash(s[i]);
	}
	reverse(s.begin(),s.end());
	rep(i,n){
		rR[i+1] = rR[i] + rolling_hash(s[i]);
	}
	
	reverse(s.begin(),s.end());
	set<rolling_hash> ss;
	vector<pair<int,int>> p;
	rep(i,n){
		int ok = 0,ng = n;
		while(ng-ok>1){
			int mid = (ok+ng)/2;
			int l = i-mid,r = i+1+mid;
			if(l<0||r>n){
				ng = mid;
				continue;
			}
			if((R[r]-R[l]) == (rR[n-l] - rR[n-r]))ok = mid;
			else ng = mid;
		}
		int l = i-ok,r = i+1+ok;
		while(l<r){
			if(ss.count(R[r]-R[l]))break;
			ss.insert(R[r]-R[l]);
			p.emplace_back(l,r);
			l++;
			r--;
		}
	}
	
	rep(i,n-1){
		if(s[i]!=s[i+1])continue;
		int ok = 0,ng = n;
		while(ng-ok>1){
			int mid = (ok+ng)/2;
			int l = i-mid,r = i+2+mid;
			if(l<0||r>n){
				ng = mid;
				continue;
			}
			if((R[r]-R[l]) == (rR[n-l] - rR[n-r]))ok = mid;
			else ng = mid;
		}
		int l = i-ok,r = i+2+ok;
		while(l<r){
			if(ss.count(R[r]-R[l]))break;
			ss.insert(R[r]-R[l]);
			p.emplace_back(l,r);
			l++;
			r--;
		}
	}
	sort(p.begin(),p.end());
	auto sa = suffix_array(s);
	auto la = lcp_array(s,sa);
	segtree<int,op,e> seg(la);
	vector<long long> imos(n+1);
	rep(i,sa.size()){
		int d = distance(p.begin(),lower_bound(p.begin(),p.end(),make_pair(sa[i],-1)));
		for(int j=d;j<p.size();j++){
			if(p[j].first!=sa[i])break;
			int len = p[j].second - p[j].first;
			X = len;
			int ll = seg.min_left<f>(i);
			int rr = seg.max_right<f>(i);
			rr++;
			long long t = rr-ll;
			t *= len;
			imos[ll] += t;
			imos[rr] -= t;
			
		}
	}
	rep(i,n)imos[i+1] += imos[i];
	cout<<(*max_element(imos.begin(),imos.end()))<<endl;
	
	return 0;
}
0