結果

問題 No.515 典型LCP
ユーザー myantamyanta
提出日時 2017-05-09 12:05:32
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,195 bytes
コンパイル時間 725 ms
コンパイル使用メモリ 74,152 KB
実行使用メモリ 152,544 KB
最終ジャッジ日時 2023-10-12 21:43:40
合計ジャッジ時間 5,421 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<map>
#include<string>
#include<algorithm>


using namespace std;
using ll=long long;
using pcpi=pair<char*,int>;
using vmii=vector<map<int,int> >;


vector<char*> s;
vmii dp;


void swap(int& a, int& b)
{
	int c;
	c=a;
	a=b;
	b=c;
}


int lcp(const char* p, const char* q)
{
	int i;

	for(i=0;p[i];i++)
	{
		if(p[i]!=q[i]) break;
	}

	return i;
}


void min_u(int& m, int v)
{
	if(m>v) m=v;
}


int get_lcp(int i, int j)
{
	swap(i, j);
	if(dp[i].find(j)!=dp[i].end()) return dp[i][j];

	return dp[i][j]=lcp(s[i], s[j]);
}


int main(void)
{
	vector<char> buf;
	int i, j, k, m;
	ll x, result, n, d;
	char *p;

	while(scanf("%lld", &n)==1)
	{
		dp.clear();
		dp.resize(n);
		s.resize(n);
		buf.resize(800000+100000);
		p=&buf[0];
		for(i=0;i<n;i++)
		{
			scanf("%s", p);
			s[i]=p;
			p+=strlen(p)+1;
		}

		result=0;
		scanf("%d%lld%lld", &m, &x, &d);
		for(k=0;k<m;k++)
		{
			i=(x/(n-1))+1;
			j=(x%(n-1))+1;
			if(i>j) swap(i, j);
			else j++;
			x=(x+d)%(n*(n-1));
			result+=get_lcp(i-1, j-1);
//			printf("k=%d  x=%d  i=%d  j=%d  %lld\n", k, x, i, j, result);
		}
		printf("%lld\n", result);
	}

	return 0;
}

0