結果

問題 No.515 典型LCP
ユーザー vjudge1
提出日時 2025-03-17 20:53:15
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 919 bytes
コンパイル時間 1,887 ms
コンパイル使用メモリ 196,544 KB
実行使用メモリ 133,044 KB
最終ジャッジ日時 2025-03-17 20:53:23
合計ジャッジ時間 6,775 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 13 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const int N=800010;
int t[N][26];
int cnt;
vector<int>id[N];
string s[N];
void insert(string s,int idd){
	int root=0,len;
	for(int i=0;i<s.size();i++){
		int x=s[i]-'a';
		if(!t[root][x])t[root][x]=++cnt;
		root=t[root][x];
		id[idd].push_back(root);
	}
	return;
}
int n;
long long m,x,d;
long long ans;
long long cal(int a,int b){
	int res=0;
	int l=1,r=min((int)s[a].size(),(int)s[b].size()),mid;
	while(l<=r){
		mid=(l+r)>>1;
		if(id[a][mid-1]==id[b][mid-1]){
			res=mid;
			l=mid+1;
		}
		else r=mid-1; 
	}
	return res;
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>s[i];
		insert(s[i],i);
	}
	cin>>m>>x>>d;
	while(m--){
		long long a=x/(n-1)+1;
		long long b=x%(n-1)+1;
		if(a>b)swap(a,b);
		else b++;
//		cerr<<a<<" "<<b<<"\n";
		ans+=cal(a,b);
		x=(x+d)%(n*(n-1));
	}
	cout<<ans<<"\n";
	return 0;
}
0