結果

問題 No.515 典型LCP
ユーザー olpheolphe
提出日時 2017-05-05 23:21:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 401 ms / 1,000 ms
コード長 1,440 bytes
コンパイル時間 1,257 ms
コンパイル使用メモリ 111,164 KB
実行使用メモリ 63,856 KB
最終ジャッジ日時 2023-10-12 11:06:55
合計ジャッジ時間 6,605 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 262 ms
63,856 KB
testcase_01 AC 298 ms
63,836 KB
testcase_02 AC 319 ms
63,212 KB
testcase_03 AC 5 ms
11,628 KB
testcase_04 AC 5 ms
11,472 KB
testcase_05 AC 328 ms
63,216 KB
testcase_06 AC 363 ms
63,200 KB
testcase_07 AC 312 ms
63,328 KB
testcase_08 AC 365 ms
63,236 KB
testcase_09 AC 309 ms
63,336 KB
testcase_10 AC 139 ms
63,336 KB
testcase_11 AC 133 ms
63,236 KB
testcase_12 AC 134 ms
63,312 KB
testcase_13 AC 382 ms
63,148 KB
testcase_14 AC 14 ms
18,640 KB
testcase_15 AC 324 ms
63,088 KB
testcase_16 AC 401 ms
63,032 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;

long long int i[3000000];
long long 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' + 37) + (43 - (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 ;
		}
		ans += l + 1;
		//cout << ans << endl;
	}
	cout << ans << endl;

	return 0;
}
0