結果

問題 No.515 典型LCP
ユーザー creep04creep04
提出日時 2018-03-15 11:12:20
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,446 bytes
コンパイル時間 3,034 ms
コンパイル使用メモリ 172,764 KB
実行使用メモリ 13,360 KB
最終ジャッジ日時 2023-08-22 06:47:03
合計ジャッジ時間 14,316 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 AC 760 ms
9,092 KB
testcase_03 AC 4 ms
7,412 KB
testcase_04 AC 4 ms
7,412 KB
testcase_05 AC 244 ms
9,144 KB
testcase_06 AC 412 ms
9,088 KB
testcase_07 AC 288 ms
9,180 KB
testcase_08 AC 477 ms
9,148 KB
testcase_09 AC 486 ms
9,176 KB
testcase_10 AC 733 ms
9,080 KB
testcase_11 AC 730 ms
8,980 KB
testcase_12 AC 724 ms
8,992 KB
testcase_13 AC 360 ms
9,228 KB
testcase_14 AC 15 ms
9,072 KB
testcase_15 AC 128 ms
9,116 KB
testcase_16 AC 131 ms
9,316 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,2<<25);
	}
	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 2<<25;
		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));
	}
	void show() {
		for (int i = 0; i < 2*n-1; ++i) {
			cout << i << ' ' << node[i] << endl;
		}
	}
};

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

int main() {
	
	cin.tie(0);
	ios::sync_with_stdio(0);
	
	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; ++i) r[p[i].second] = i;
	RMQ<int> lcp(n);
	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) {
		long long a = x/(n-1), b = x%(n-1);
		if (a>b) swap(a,b);
		else b++;
		x = (x+d) % (n*(n-1));
		int ra = r[a], rb = r[b];
		if (ra>rb) swap(ra,rb);
		//cout << a << ' ' << b << ' ' << lcp.q(ra,rb) << endl;
		ans += lcp.q(ra,rb);
	}
	cout << ans << endl;
}
0