結果

問題 No.515 典型LCP
ユーザー %20%20
提出日時 2020-02-08 04:30:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 413 ms / 1,000 ms
コード長 766 bytes
コンパイル時間 1,987 ms
コンパイル使用メモリ 207,088 KB
実行使用メモリ 119,696 KB
最終ジャッジ日時 2023-10-26 00:39:21
合計ジャッジ時間 8,204 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 387 ms
119,696 KB
testcase_01 AC 359 ms
119,696 KB
testcase_02 AC 326 ms
113,096 KB
testcase_03 AC 102 ms
109,532 KB
testcase_04 AC 102 ms
109,532 KB
testcase_05 AC 373 ms
112,832 KB
testcase_06 AC 392 ms
112,832 KB
testcase_07 AC 369 ms
112,832 KB
testcase_08 AC 393 ms
112,832 KB
testcase_09 AC 286 ms
112,832 KB
testcase_10 AC 190 ms
112,832 KB
testcase_11 AC 190 ms
112,832 KB
testcase_12 AC 189 ms
112,832 KB
testcase_13 AC 386 ms
113,096 KB
testcase_14 AC 113 ms
113,060 KB
testcase_15 AC 363 ms
113,144 KB
testcase_16 AC 413 ms
113,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){cin.tie(0);ios::sync_with_stdio(false);
	vector<vector<int>>Trie(800001,vector<int>(26));
	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 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(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