結果

問題 No.515 典型LCP
ユーザー %20%20
提出日時 2020-02-08 03:47:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 414 ms / 1,000 ms
コード長 743 bytes
コンパイル時間 2,237 ms
コンパイル使用メモリ 201,728 KB
実行使用メモリ 88,052 KB
最終ジャッジ日時 2023-10-26 00:38:49
合計ジャッジ時間 6,831 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 199 ms
58,744 KB
testcase_01 AC 160 ms
7,188 KB
testcase_02 AC 261 ms
6,892 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 373 ms
88,044 KB
testcase_06 AC 407 ms
88,044 KB
testcase_07 AC 357 ms
88,044 KB
testcase_08 AC 414 ms
88,044 KB
testcase_09 AC 229 ms
7,004 KB
testcase_10 AC 88 ms
7,212 KB
testcase_11 AC 88 ms
7,016 KB
testcase_12 AC 89 ms
7,012 KB
testcase_13 AC 351 ms
8,832 KB
testcase_14 AC 15 ms
10,860 KB
testcase_15 AC 346 ms
88,052 KB
testcase_16 AC 377 ms
88,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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