結果

問題 No.515 典型LCP
ユーザー umaumaxumaumax
提出日時 2017-05-06 00:37:31
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 961 bytes
コンパイル時間 640 ms
コンパイル使用メモリ 69,196 KB
実行使用メモリ 80,732 KB
最終ジャッジ日時 2023-10-12 10:52:31
合計ジャッジ時間 3,926 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 TLE -
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 <iostream>
#include <map>

using namespace std;

int main(int argc, const char* argv[])
{
	uint64_t N;
	cin >> N;
	string S[N];
	for (auto&& c : S) cin >> c;
	int M, x, d;
	cin >> M >> x >> d;
	uint64_t i[M + 1];
	uint64_t j[M + 1];
	map<pair<int, int>, int> m;
	auto f = [&](int ik, int jk) {
		//	NOTE ik <= jk
		pair<int, int> key = {ik, jk};
		if (m[key]) return m[key];

		int cnt = 0;
		if (ik == jk) {
			cnt = S[ik].size();
		}
		else {
			for (int i = 0; i < S[ik].size() && i < S[jk].size(); i++) {
				if (S[ik][i] == S[jk][i])
					cnt++;
				else
					break;
			}
		}
		m[key] = cnt;
		return cnt;
	};

	for (int k = 1; k <= M; k++) {
		i[k] = (x / (N - 1)) + 1;
		j[k] = (x % (N - 1)) + 1;
		if (i[k] > j[k])
			swap(i[k], j[k]);
		else
			j[k] = j[k] + 1;

		x = (x + d) % (N * (N - 1));
	}
	int sum = 0;
	for (int k = 1; k <= M; k++) {
		int ik = i[k] - 1;
		int jk = j[k] - 1;
		sum += f(ik, jk);
	}
	cout << sum << endl;
	return 0;
}
0