結果

問題 No.515 典型LCP
ユーザー 👑 kmjpkmjp
提出日時 2017-05-06 03:50:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 287 ms / 1,000 ms
コード長 1,433 bytes
コンパイル時間 2,904 ms
コンパイル使用メモリ 155,124 KB
実行使用メモリ 19,008 KB
最終ジャッジ日時 2023-10-12 13:17:23
合計ジャッジ時間 6,077 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 287 ms
18,768 KB
testcase_01 AC 285 ms
19,008 KB
testcase_02 AC 144 ms
14,556 KB
testcase_03 AC 5 ms
12,796 KB
testcase_04 AC 6 ms
12,640 KB
testcase_05 AC 89 ms
14,316 KB
testcase_06 AC 96 ms
14,328 KB
testcase_07 AC 91 ms
14,340 KB
testcase_08 AC 126 ms
14,384 KB
testcase_09 AC 99 ms
14,368 KB
testcase_10 AC 100 ms
14,208 KB
testcase_11 AC 100 ms
14,208 KB
testcase_12 AC 100 ms
14,296 KB
testcase_13 AC 91 ms
14,328 KB
testcase_14 AC 9 ms
14,296 KB
testcase_15 AC 82 ms
14,296 KB
testcase_16 AC 82 ms
14,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


ll N;
string S[101010];
pair<string,int> P[101010];
int ID[101010];
ll M,X,D;

int com[101010][20];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>S[i];
		P[i]={S[i],i};
	}
	sort(P,P+N);
	FOR(i,N) ID[P[i].second]=i;
	FOR(i,N-1) {
		x=P[i].second;
		y=P[i+1].second;
		FOR(r,min(S[x].size(),S[y].size())) if(S[x][r]!=S[y][r]) break;
		com[i][0]=r;
	}
	for(x=1;x<=19;x++) FOR(i,N-1) if(i+(1<<(x-1))<N) com[i][x]=min(com[i][x-1],com[i+(1<<(x-1))][x-1]);
	
	ll ret=0;
	cin>>M>>X>>D;
	for(int k=1;k<=M;k++) {
		x=X/(N-1);
		y=X%(N-1);
		if(x>y) swap(x,y);
		else y++;
		X = (X+D) % (N*(N-1));
		
		x=ID[x];
		y=ID[y];
		if(x>y) swap(x,y);
		
		r=0;
		while(1<<(1+r)<=y-x) r++;
		
		ret += min(com[x][r],com[y-(1<<r)][r]);
		
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0