結果

問題 No.515 典型LCP
ユーザー %20%20
提出日時 2020-02-08 03:28:20
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 614 ms / 1,000 ms
コード長 722 bytes
コンパイル時間 2,457 ms
コンパイル使用メモリ 195,676 KB
最終ジャッジ日時 2025-01-08 22:53:56
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 15
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:7:20: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |         int N;scanf("%d%*c",&N);
      |               ~~~~~^~~~~~~~~~~~
main.cpp:19:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   19 |         int M;long X,D;scanf("%d%ld%ld%*c",&M,&X,&D);
      |                        ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

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