結果

問題 No.515 典型LCP
ユーザー olpheolphe
提出日時 2017-05-05 23:11:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,473 bytes
コンパイル時間 959 ms
コンパイル使用メモリ 111,960 KB
実行使用メモリ 40,472 KB
最終ジャッジ日時 2023-10-12 10:10:56
合計ジャッジ時間 6,496 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 309 ms
40,472 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 5 ms
11,544 KB
testcase_04 AC 5 ms
11,516 KB
testcase_05 AC 335 ms
39,708 KB
testcase_06 AC 367 ms
39,820 KB
testcase_07 AC 321 ms
39,840 KB
testcase_08 AC 369 ms
39,700 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 333 ms
39,472 KB
testcase_16 AC 416 ms
39,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

int i[3000000];
int j[3000000];

long long int N;
string s[100001];
int si[100001];
long long int M, x, d;
long long int ans;
vector<long long int>sum[100001];

int main() {
	ios::sync_with_stdio(false);
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> s[i];
		si[i] = (int)s[i].size();
		sum[i].resize(si[i]);
		sum[i][0] = MOD*(int)(s[i][0] - 'a') + (26 - s[i][0] - 'a');
		for (int j = 1; j < si[i]; j++) {
			sum[i][j] = sum[i][j - 1] * (int)(s[i][j] - 'a'+27) + (26 - (s[i][j] - 'a'));
		}
		//for (int j = 0; j < si[i]; j++)cout << sum[i][j] << " ";
		//cout << endl;
	}
	cin >> M >> x >> d;
	for (int k = 0; 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));
	}
	for (int k = 0; k < M; k++) {
		int l = -1;
		int r = min(si[i[k]], si[j[k]]) ;
		while (r - l > 1) {
			int mid = (r + l) / 2;
			if (sum[i[k]][mid] == sum[j[k]][mid])l = mid;
			else r = mid;
		}
		if (s[i[k]][l+1] == s[j[k]][l+1])ans += l + 2;
		else ans += l + 1;
		//cout << ans << endl;
	}
	cout << ans << endl;

	return 0;
}
0