結果

問題 No.515 典型LCP
ユーザー tansunogontansunogon
提出日時 2017-05-05 23:21:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,137 bytes
コンパイル時間 504 ms
コンパイル使用メモリ 69,708 KB
実行使用メモリ 7,492 KB
最終ジャッジ日時 2023-10-12 10:18:05
合計ジャッジ時間 3,946 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 4 ms
6,656 KB
testcase_04 AC 4 ms
6,548 KB
testcase_05 AC 50 ms
7,356 KB
testcase_06 AC 54 ms
7,344 KB
testcase_07 AC 53 ms
7,336 KB
testcase_08 AC 57 ms
7,404 KB
testcase_09 AC 182 ms
7,216 KB
testcase_10 AC 95 ms
7,408 KB
testcase_11 AC 108 ms
7,152 KB
testcase_12 AC 107 ms
7,160 KB
testcase_13 TLE -
testcase_14 AC 6 ms
7,220 KB
testcase_15 AC 47 ms
7,360 KB
testcase_16 AC 47 ms
7,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

struct iostream_init_struct
{ 
	iostream_init_struct()
	{
		std::cin.tie(0);
		std::cin.sync_with_stdio(false);
	}
} iostream_init;

#include <string>
#include <vector>
#include <algorithm>
int N;
string s[100000];
int M, x, d, i, j;

void next()
{
	i = (x / (N - 1));
	j = (x % (N - 1));
	if (i > j)
	{
		int temp = i;
		i = j;
		j = temp;
	}
	else
	{
		j = j + 1;
	}
	x = (x + d) % (N * (N - 1));
}

int LCP()
{
	int ret = 0;
	int length = min(s[i].size(), s[j].size());
	const char* si = s[i].data();
	const char* sj = s[j].data();
	const uint64_t* s64i = reinterpret_cast<const uint64_t*>(si);
	const uint64_t* s64j = reinterpret_cast<const uint64_t*>(sj);
	while (ret < length / 8)
	{
		if (s64i[ret] == s64j[ret])
		{
			++ret;
		}
		else
		{
			break;
		}
	}
	ret *= 8;
	while (ret < length)
	{
		if (si[ret] == sj[ret])
		{
			++ret;
		}
		else
		{
			break;
		}
	}

	return ret;
}

int main()
{
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> s[i];
	}
	cin >> M >> x >> d;

	int sum = 0;
	for (int indx = 0; indx < M; ++indx)
	{
		next();
		sum += LCP();
	}

	cout << sum << endl;
}
0