結果

問題 No.515 典型LCP
ユーザー creep04creep04
提出日時 2018-03-15 09:49:49
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,327 bytes
コンパイル時間 3,199 ms
コンパイル使用メモリ 172,164 KB
実行使用メモリ 14,484 KB
最終ジャッジ日時 2023-08-22 01:42:21
合計ジャッジ時間 13,286 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 5 ms
7,420 KB
testcase_04 AC 5 ms
7,436 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 438 ms
9,392 KB
testcase_16 AC 453 ms
9,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

// RMQ<int> rmq(114514);
template<typename V> struct RMQ {
	private:
	int n;
	vector<V> node;
	public:
	RMQ(int sz) {
		n=1;while(n<sz)n*=2;
		node.resize(2*n-1,1145141919);
	}
	void update(int x, V val) {
		x+=n-1,node[x]=val;
		while(x>0) x=(x-1)/2,node[x]=min(node[2*x+1],node[2*x+2]);
	}
	V q(int a, int b, int k=0, int l=0, int r=-1) {
		if(r<0) r=n;
		if(r<=a||b<=l) return 1145141919;
		if(a<=l&&r<=b) return node[k];
		return min(q(a,b,2*k+1,l,(l+r)/2),q(a,b,2*k+2,(l+r)/2,r));
	}
};

int n, m, r[114514];
long long x, d, ans;
string s[114514];
vector<pair<string,int>> p;
RMQ<int> lcp(114514);

int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> s[i];
		p.push_back({s[i],i});
	}
	
	sort(p.begin(), p.end());
	for (int i = 0; i < n-1; ++i) r[p[i].second] = i;
	for (int i = 0; i < n-1; ++i) {
		int j = 0;
		for (; j < min(p[i].first.size(), p[i+1].first.size()); ++j) {
			if (p[i].first[j]!=p[i+1].first[j]) break;
		}
		lcp.update(i,j);
	}
	
	cin >> m >> x >> d;
	for (int i = 1; i <= m; ++i) {
		int a = x/(n-1) + 1, b = x%(n-1) + 1;
		if (a>b) swap(a,b);
		else b++;
		x = (x+d) % (n*(n-1));
		//cout << a << ' ' << b << ' ' << lcp.q(r[a-1],r[b-1]) << endl;
		int inc = lcp.q(r[a-1],r[b-1]);
		if (inc!=1145141919) ans += inc;
	}
	cout << ans << endl;
}
0