結果

問題 No.515 典型LCP
コンテスト
ユーザー %20
提出日時 2020-02-08 03:47:09
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 124 ms / 1,000 ms
コード長 743 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,376 ms
コンパイル使用メモリ 210,336 KB
実行使用メモリ 88,320 KB
最終ジャッジ日時 2026-06-08 17:49:43
合計ジャッジ時間 3,641 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;

int Trie[800001][26];
int d[800000];
int start[100001];

int main(){
	int N;scanf("%d%*c",&N);
	int s=1,j=0;
	for(int i=0;i<N;++i){
		int p=0;
		start[i]=j;
		for(int c;c=getchar(),c!='\n';){
			c-='a';
			p=Trie[p][c]=Trie[p][c]?:s++;
			d[j++]=p;
		}
	}
	start[N]=j;
	int M;long long X,D;scanf("%d%lld%lld%*c",&M,&X,&D);
	long long NN=N*(long long)(N-1),z=0;
	X%=NN;
	D%=NN;
	--N;
	for(int _=0;_<M;++_){
		int i=X/N,j=X%N;
		if(i>j){
			swap(i,j);
		}else{
			++j;
		}
		X+=D;
		if(X>=NN){
			X-=NN;
		}
		int ok=0,ng=min(start[i+1]-start[i],start[j+1]-start[j])+1;
		while(ng-ok>1){
			int k=ok+ng>>1;
			(d[start[i]-1+k]==d[start[j]-1+k]?ok:ng)=k;
		}
		z+=ok;
	}
	cout<<z<<"\n";
	return 0;
}
0