結果

問題 No.515 典型LCP
ユーザー %20%20
提出日時 2020-02-08 03:26:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 473 ms / 1,000 ms
コード長 720 bytes
コンパイル時間 2,106 ms
コンパイル使用メモリ 205,148 KB
実行使用メモリ 87,908 KB
最終ジャッジ日時 2023-10-26 00:37:35
合計ジャッジ時間 7,706 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 473 ms
65,072 KB
testcase_01 AC 339 ms
13,568 KB
testcase_02 AC 235 ms
6,880 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 356 ms
87,860 KB
testcase_06 AC 377 ms
87,860 KB
testcase_07 AC 351 ms
87,860 KB
testcase_08 AC 384 ms
87,860 KB
testcase_09 AC 194 ms
6,768 KB
testcase_10 AC 91 ms
7,360 KB
testcase_11 AC 90 ms
7,164 KB
testcase_12 AC 90 ms
7,160 KB
testcase_13 AC 301 ms
8,936 KB
testcase_14 AC 19 ms
10,844 KB
testcase_15 AC 346 ms
87,908 KB
testcase_16 AC 406 ms
87,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int Trie[800001][26];

int main(){cin.tie(0);ios::sync_with_stdio(false);
	int N;scanf("%d%*c",&N);
	int s=1;
	vector<vector<int>>d(N);
	for(int i=0;i<N;++i){
		int p=0;
		d[i].push_back(p);
		for(int c;c=getchar(),c!='\n';){
			c-='a';
			p=Trie[p][c]=Trie[p][c]?:s++;
			d[i].push_back(p);
		}
	}
	int M;long X,D;scanf("%d%ld%ld%*c",&M,&X,&D);
	long NN=N*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(d[i].size(),d[j].size());
		while(ng-ok>1){
			int k=ok+ng>>1;
			(d[i][k]==d[j][k]?ok:ng)=k;
		}
		z+=ok;
	}
	cout<<z<<"\n";
	return 0;
}
0