結果

問題 No.515 典型LCP
ユーザー e869120
提出日時 2017-05-05 22:37:11
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 827 bytes
コンパイル時間 1,033 ms
コンパイル使用メモリ 84,376 KB
実行使用メモリ 111,872 KB
最終ジャッジ日時 2024-09-14 08:52:03
合計ジャッジ時間 6,003 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 2
other TLE * 1 -- * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
using namespace std;
long long N, M, x, d, sum; string S[100009]; vector<long long>E[100009]; map<pair<long long, long long>, int>MM;
int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> S[i];
	}
	cin >> M >> x >> d;
	for (int i = 1; i <= M; i++) {
		long long A = (x / (N - 1)) + 1;
		long long B = (x % (N - 1)) + 1;
		if (A > B)swap(A, B);
		else B = B + 1;
		x = (x + d) % (N * (N - 1));

		if (MM[make_pair(A, B)] >= 1) {
			sum += MM[make_pair(A, B)] - 1;
		}
		else {
			long long cnt = 0;
			for (int j = 0; j < 1000000; j++) {
				if (S[A].size() <= j || S[B].size() <= j)break;
				if (S[A][j] != S[B][j])break;
				cnt++;
			}
			sum += cnt;
			MM[make_pair(A, B)] = cnt + 1;
		}
	}
	cout << sum << endl;
	return 0;
}
0