QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#671519#8334. GeneHuHu_FeiWA 248ms18176kbC++143.4kb2024-10-24 13:05:462024-10-24 13:05:47

Judging History

你现在查看的是最新测评结果

  • [2024-10-24 13:05:47]
  • 评测
  • 测评结果:WA
  • 用时:248ms
  • 内存:18176kb
  • [2024-10-24 13:05:46]
  • 提交

answer

#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;

using i64 = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;

const int N = 1000010,M = 200010,mod = 1e9+7,INF = 0X3f3f3f3f;

mt19937_64 rnd(chrono::duration_cast<chrono::nanoseconds>(chrono::system_clock::now().time_since_epoch()).count());

int Tn,n,q,m,k;
string s;
int x[N << 1],y[N],c[N],sa[N],rk[N],height[N],mn[N][25],mylog2[N];
//sa[i]表示排序为i的后缀编号
//rk[i]表示后缀i的排名
//height[i] = lcp(sa[i],sa[i - 1]) 第i名后缀与第i-1名后缀的最长公共前缀的长度

//空间够的话开两倍空间,这个模板有点丑会越界

void get_sa() {
	int i,j,k;
	for (i = 1;i <= n;i++) {
		c[x[i] = s[i]] ++;
		m = max(m,(int)s[i]);
	}
	for (i = 1;i <= m;i++) {
		c[i] += c[i - 1];
	}
	for (i = n;i >= 1;i--) {
		sa[c[x[i]]--] = i;
	}
	// cerr << m << "\n";

	for (k = 1;k <= n;k <<= 1) {
		for (i = 0;i <= m;i++) c[i] = 0;
		for (i = 1;i <= n;i++) {
			y[i] = sa[i];
		}
		for (i = 1;i <= n;i++) {
			c[x[y[i] + k]]++;
		}
		for (i = 1;i <= m;i++) {
			c[i] += c[i-1];
		}
		for (i = n;i >= 1;i--) {
			sa[c[x[y[i] + k]]--] = y[i]; //x[y[i] + k] 会越界
		}

		for (i = 0;i <= m;i++) c[i] = 0;
		for (i = 1;i <= n;i++) {
			y[i] = sa[i];
		} 
		for (i = 1;i <= n;i++) {
			c[x[y[i]]]++; 
		}
		for (i = 1;i <= m;i++) {
			c[i] += c[i-1];
		}
		for (i = n;i >= 1;i--) {
			sa[c[x[y[i]]]--] = y[i]; 
		}

		for (i = 1;i <= n;i++) {
			y[i] = x[i];
		}
		for (m = 0,i = 1;i <= n;i++) {
			if (y[sa[i]] == y[sa[i-1]] && y[sa[i] + k] == y[sa[i-1] + k]) x[sa[i]] = m;
			else x[sa[i]] = ++m;
		}
		if (m == n) break;
	} 
}

void get_height() {
	for (int i = 1;i <= n;i++) {
		rk[sa[i]] = i;
	}
	for (int i = 1,k = 0;i <= n;i++) {
		if (rk[i] == 1) continue;
		if (k) k--;
		int j = sa[rk[i] - 1];
		while (i + k <= n && j + k <= n && s[i + k] == s[j + k]) k++;
		height[rk[i]] = k;
	}

	for (int i = 1;i <= n;i++) {
		mn[i][0] = height[i];
	}
	for (int j = 1;j <= 24;j++) {
		for (int i = 1;i <= n - (1 << j) + 1;i++) {
			mn[i][j] = min(mn[i][j - 1],mn[i + (1 << j - 1)][j - 1]);
		}
	}
	mylog2[1] = 0;
	for (int i = 2;i < n;i++) {
		mylog2[i] = mylog2[i >> 1] + 1;
	}
}

//求后缀a和后缀b的lcp
int lcp(int a,int b) {
	a = rk[a], b = rk[b];
	if (a > b) swap(a,b);
	a += 1;
	int k = mylog2[b - a + 1];
	return min(mn[a][k],mn[b - (1 << k) + 1][k]);
}

//清空
void init(int n) {
	for (int i = 1;i <= 2 * n;i++) {
		x[i] = y[i] = sa[i] = rk[i] = height[i] = 0;
		memset(mn[i],0,sizeof mn[i]);
	}
	for (int i = 1;i <= 256;i++) {
		c[i] = 0;
	}
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> Tn >> q >> m >> k;
	vector<string> S(Tn);
	for (int i = 0;i < Tn;i++) {
		cin >> S[i];
		// cerr << 
	}

	while (q--) {
		string t;
		cin >> t;
		int ans = 0;
		for (int i = 0;i < Tn;i++) {
			s = S[i] + t;
			s = " " + s;
			n = s.size() - 1;
			init(n);
			get_sa();
			get_height();

			int p = 1,q = n / 2 + 1;
			int cnt = 0;
			while (p <= n / 2 && q <= n && cnt <= k) {
				int same = lcp(p,q);
				if (same == 0) {
					cnt++;
					p++,q++;
					continue;
				}
				p = p + same + 1;
				q = q + same + 1;
				if (p <= n / 2 && q <= n) cnt++;
			}
			// cerr << "cnt = " << cnt << "\n";
			if (cnt <= k) ans++;
		}
		cout << ans << "\n";
	}

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 18004kb

input:

6 4 4 1
kaki
kika
manu
nana
tepu
tero
kaka
mana
teri
anan

output:

2
2
1
0

result:

ok 4 number(s): "2 2 1 0"

Test #2:

score: 0
Accepted
time: 3ms
memory: 17944kb

input:

8 6 7 3
delphis
aduncus
peronii
plumbea
clymene
hectori
griseus
electra
delphis
helpiii
perphii
clumeee
eleelea
ddlpcus

output:

1
1
2
2
1
2

result:

ok 6 numbers

Test #3:

score: 0
Accepted
time: 101ms
memory: 18176kb

input:

300 300 9 10
dmzampmxe
bteaudaxb
fjfwhhsfq
btnfzqtyp
ijjrkbyht
hkizlvgdc
ukwsnhiff
hacsdrwyl
fbjabnhst
ktsxbgbtg
jopdbsdsr
yxdxxjltd
daechsouq
klrglgwbn
llzhqzlor
ckdedutfn
lkjxcryoe
zvusjevtz
cevrcdltg
tdmmvvpkj
davfsweem
spcfhcitm
aohsfqrqh
lblehevpj
soaqryimp
tbxlulxmn
tnlzbkhda
ukfhjykuk
eghpuua...

output:

300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
...

result:

ok 300 numbers

Test #4:

score: 0
Accepted
time: 111ms
memory: 18172kb

input:

300 300 10 10
qoecfhznxd
hkoaiunzim
lhtzdmbrjs
vqesfzpiuv
amsgqjxmbq
vptwyshswk
sofrfmsrpf
eplnexhmoh
gcjtqavjga
azytravylz
akpuemdfpq
oxkacujrhg
bsgieguzuo
bojvtfkbdf
pmqmrbceej
zgpfkqfeyx
qkdbfrxqcj
effpkigdcw
kqyqmgjdzr
czlbscrnaq
rymhkenugz
fuybclhlhj
rtmclsdvwy
rhfbfqfrfs
bpemthjxfi
jtcvqyltgj
...

output:

300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
300
...

result:

ok 300 numbers

Test #5:

score: 0
Accepted
time: 114ms
memory: 17904kb

input:

300 300 11 10
lonodhfyrbj
njzuczzviuj
usovdmjfjco
bljtnmsjhut
kkkeybjagck
tbuivwfvjit
qhjzqocsvod
ayobjbagcgv
dudupzsvqpe
tcapottzyte
wdevxapvocr
hsvdfaahndr
jjplhydycgn
srrtpmqmygw
gjjbcchwcur
uivvuqldryj
amlidxfsobz
ofpnwqrzhly
eolqcyidojx
jpiybuplwcf
jmxxtjnwsru
ivkbixrgnph
txjjppqkxgu
vmmbwxmvjd...

output:

96
109
114
108
108
95
108
109
113
106
104
94
111
108
95
107
91
99
111
101
105
116
117
109
106
115
116
96
108
95
114
87
94
116
95
97
104
107
91
103
103
92
115
103
120
102
115
103
101
105
108
95
118
106
91
98
99
115
101
106
120
91
118
91
111
99
104
101
104
96
98
116
111
110
107
118
94
96
103
107
108
1...

result:

ok 300 numbers

Test #6:

score: 0
Accepted
time: 196ms
memory: 18104kb

input:

300 300 11 10
bacdccbdbba
ccabcddcbdc
ddbcccadbab
cbdcabcddbd
ccddbaacaba
addabdbbcba
ccbcbadadac
cbadacadcbb
abddacbcada
ccccbdccdda
dadcbdbddda
acbdccdbcdc
bbbbdbcdcbc
cdcbabdacda
acbcdaaadbc
dccbdcddcca
abbacddccba
cccabdcacda
ddcadbabbca
babaaabbabd
dabdaacaddc
cabcacbdcda
cdbbbdcddcd
cdbdccadda...

output:

287
292
286
279
286
285
289
289
294
284
287
291
287
286
283
275
284
291
289
289
286
291
287
282
290
282
278
288
285
285
285
289
287
283
287
290
287
288
292
288
286
290
290
288
289
285
289
276
286
289
283
279
288
288
288
289
289
286
281
288
291
290
287
289
285
280
289
287
286
295
284
285
286
279
284
...

result:

ok 300 numbers

Test #7:

score: -100
Wrong Answer
time: 248ms
memory: 18020kb

input:

300 300 15 10
bbjbbbjbjbbjjbb
bbjbbbbjbjjjbbb
jbjjjjbjbbjbjbb
bbjjjbjbbjbbjbb
bjbjjjbbbbbbbbb
bjbjbjjjbjjjjjj
bbbjjbbjjjbjjjb
bjbbjbjbjbjjjjj
bbbbbjbjjjjbjbj
bbbjbbbbjbjjjjb
jjjbbbbbbbjjbbj
jbbjjjbbbbjbjbb
bjjbbjbjbjbjjjj
bbjbbjbjbjjbbbb
jbjjjjbbbbjjjbj
bbbbjbbbbbjjbjj
jbjbjjbbjjbjjjb
jjbjbjjbbbjjjj...

output:

283
286
292
285
286
282
284
282
287
281
289
293
281
282
282
287
281
283
283
286
286
284
290
280
289
287
287
280
287
285
290
282
288
286
278
291
289
283
285
290
291
279
282
281
289
290
277
276
283
289
284
284
283
282
288
287
278
284
285
282
285
285
294
281
289
283
288
290
289
279
280
287
287
286
281
...

result:

wrong answer 1st numbers differ - expected: '279', found: '283'