QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#683569#8334. GeneONISINOWA 8ms3716kbC++203.1kb2024-10-27 21:54:142024-10-27 21:54:16

Judging History

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

  • [2024-10-27 21:54:16]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:3716kb
  • [2024-10-27 21:54:14]
  • 提交

answer

#include <bits/stdc++.h>

//DEBUG:    https://github.com/sharkdp/dbg-macro
#ifdef LOCAL
#include "../dbg-macro-0.5.1/dbg.h"
#else
#define dbg(...) (__VA_ARGS__)
#endif

#define endl '\n'
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double llf;
const ll MAXN=2e5+10,MOD=998244353,INF=1e9;

ll qpow(ll base,ll exp){ll ans=1;while(exp){if(exp&1)(ans*=base)%=MOD;(base*=base)%=MOD;exp>>=1;}return ans;}
template<class T>ll max_binary_answer(ll l,ll r,T check,bool cmp=true){ll m;while(l<r){m=(l+r+1)/2;if(cmp^!check(m))l=m;else r=m-1;}return l;}
template<class T>ll min_binary_answer(ll l,ll r,T check,bool cmp=true){ll m;while(l<r){m=(l+r)/2;if(cmp^!check(m))r=m;else l=m+1;}return r;}
ll exgcd(ll a,ll b,ll &x,ll &y){ll tmp;return b==0?(x=1,y=0,a):(tmp=exgcd(b,a%b,y,x),y-=(a/b)*x,tmp);}
ll highbit(ll x){for(ll i=1;i<(ll)sizeof(ll)*4;i<<=1)x|=x>>i;return x-(x>>1);}
ll lowbit(ll x){return x&(-x);}
//--------Global declared area--------
int n,q,m,k;
ull k1=114,k2=514;
vector<string> s;
vector<vector<pair<ull,ull>>> ha;
void init(){
	for(int i=0;i<n;i++){
		for(int j=1;j<=m;j++){
			ha[i][j].first=((ha[i][j-1].first*k1)+(int)(s[i][j-1]-'a'));
			ha[i][j].second=((ha[i][j-1].second*k2)+(int)(s[i][j-1]-'a'));
		}
	}
}
bool check(int x,string t,vector<pair<ull,ull>> &tha){

	ll l=1,mid,cnt=k;
	while(cnt>=0){
		ll r=m;
		
//		for(int i=1;i<=m;i++){
//			cout<<tha[i].first-tha[i-1].first*k1<<','<<tha[i].second-tha[i-1].second*k2<<"  ";
//		}cout<<endl;
//		for(int i=1;i<=m;i++){
//			cout<<ha[x][i].first-ha[x][i-1].first*k1<<','<<ha[x][i].second-ha[x][i-1].second*k2<<"  ";
//		}cout<<endl;
		
		while(l<r){
			mid=(l+r)/2;
			if(
				tha[mid].first-tha[l-1].first*k1==ha[x][mid].first-ha[x][l-1].first*k1
				&&tha[mid].second-tha[l-1].second*k2==ha[x][mid].second-ha[x][l-1].second*k2
			){
				l=mid+1;
			}else{
				r=mid;
			}
		}
		
//		cout<<l<<"  "<<r<<endl;
		
		if(
			l<=m
			&&(
				tha[r].first-tha[l-1].first*k1!=ha[x][r].first-ha[x][l-1].first*k1
				||tha[r].second-tha[l-1].second*k2!=ha[x][r].second-ha[x][l-1].second*k2
			)
		){
			cnt--;
			l=r+1;
		}else{
//			cerr<<"good"<<endl;
			return true;
		}
	}
//	cerr<<"bad"<<endl;
	return false; 
}
//--------Global declared end --------
void solve(int test_num){
	cin>>n>>q>>m>>k;
	s.resize(n);
	ha.resize(n,vector<pair<ull,ull>>(m+1,{0,0}));
	for(int i=0;i<n;i++){
		cin>>s[i];
	}
	init();
	while(q--){
		int ans=0;
		string t;
		cin>>t;
		vector<pair<ull,ull>> tha(m+1);
		for(int i=1;i<=m;i++){
			tha[i].first=((tha[i-1].first*k1)+(int)(t[i-1]-'a'));
			tha[i].second=((tha[i-1].second*k2)+(int)(t[i-1]-'a'));
		}
		for(int i=0;i<n;i++){
			ans+=check(i,t,tha);
		}
		cout<<ans<<endl;
	}
//	for(int i=0;i<n;i++){
//		cout<<s[i]<<":  ";
//		for(int j=0;j<=m;j++){
//			cout<<":"<<ha[i][j].first<<','<<ha[i][j].second<<"  ";
//		}
//		cout<<endl;
//	}
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr),std::cout.tie(nullptr);
	int t=1;
	//cin>>t;
	for(int i=1;i<=t;i++){
		solve(i);
		//cout.flush();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0ms
memory: 3580kb

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: 6ms
memory: 3660kb

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: 7ms
memory: 3716kb

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: 8ms
memory: 3680kb

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: 8ms
memory: 3620kb

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: 8ms
memory: 3592kb

input:

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

output:

288
293
294
288
292
289
285
287
290
286
294
294
286
290
293
294
285
289
290
293
289
289
291
289
295
290
294
291
292
288
295
290
295
288
285
294
295
294
290
293
294
287
286
292
293
293
285
286
288
292
291
290
290
291
291
289
286
296
290
292
293
290
293
289
290
290
292
294
294
286
289
290
293
289
289
...

result:

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