結果

問題 No.515 典型LCP
ユーザー myantamyanta
提出日時 2017-05-05 23:09:33
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 822 bytes
コンパイル時間 772 ms
コンパイル使用メモリ 42,484 KB
実行使用メモリ 8,792 KB
最終ジャッジ日時 2023-10-12 10:16:19
合計ジャッジ時間 7,964 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 TLE -
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 42 ms
4,352 KB
testcase_06 AC 43 ms
4,348 KB
testcase_07 AC 42 ms
4,352 KB
testcase_08 AC 44 ms
4,348 KB
testcase_09 TLE -
testcase_10 AC 361 ms
4,352 KB
testcase_11 AC 463 ms
4,352 KB
testcase_12 AC 464 ms
4,352 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstring>
#include<vector>


using namespace std;
using ll=long long;


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


int lcp(char *p, char *q)
{
	int i;
	for(i=0;p[i] && p[i]==q[i];i++)
		;
	return i;
}


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

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

		result=0;
		scanf("%d%d%d", &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+=lcp(s[i-1], s[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