QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#229729#7618. Pattern SearchWJH#WA 178ms3616kbC++141.2kb2023-10-28 16:45:422023-10-28 16:45:43

Judging History

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

  • [2023-10-28 16:45:43]
  • 评测
  • 测评结果:WA
  • 用时:178ms
  • 内存:3616kb
  • [2023-10-28 16:45:42]
  • 提交

answer

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

int c[30],cc[30],d[30],r[30];
pair<int,int> a[30],b[30];

void solve(){
	string s,t;cin>>s>>t;
	for(int i=0;i<26;i++){
		c[i]=cc[i]=0;
	}
	for(int i=0;i<s.length();i++){
		c[s[i]-'a']++;
	}
	for(int i=0;i<t.length();i++){
		cc[t[i]-'a']++;
	}
	int ok=1;
	for(int i=0;i<26;i++){
		a[i]={c[i],i};
		b[i]={cc[i],i};
		if(cc[i]>c[i]) ok=0;
	}
	if(!ok){
		cout<<"0\n";
		return;
	}
	sort(a,a+26);sort(b,b+26);
	int ans=0;
	for(int k=1;k<=t.length();k++){
		ok=1;int cnt=0,re=0;
		for(int i=0;i<26;i++){
			int e=cc[i]/(t.length()/k);
			r[i]=cc[i]-e*t.length()/k;
			d[i]=e;
			if(e<r[i]) ok=0;
			cnt+=e;re+=r[i];
		}
		if(ok&&((re+cnt*t.length()/k)==t.length())){
			int now=1e9;
			for(int i=0;i<26;i++)if(d[i]){
				now=min(now,c[i]/d[i]);
			}
			int res=now-t.length()/cnt,ck=1;
			for(int i=0;i<26;i++){
				int co=d[i]*now;
				co=c[i]-co;
				if(co<r[i]) ck=0;
			}
//			cout<<now<<" "<<k<<" "<<ck<<" "<<cnt<<endl;
			res+=ck;
			ans=max(ans,res);
		}
	}
	cout<<ans<<"\n";
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int T;cin>>T;
	while(T--)
	solve();
	
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
bajkaaall aal
abca cba

output:

2
1

result:

ok 2 number(s): "2 1"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

16
a a
a b
b a
aa a
ab aa
ab b
ab c
aaz az
abcde edcba
aaaaaaaaaaaabbb aaaaaaaaabb
aaaaaazz az
aaaaaaaaaz zzzzz
gggggggggggggggggggge ggggeeee
hyphyphyphyphyphyphyphyphyphyphyphyp eeeeeeeeee
hyphyphyphyphyphyphyphyphyphyphyphype eeteeteeteet
aaaabbbbbbcccccccc aaabbbbbcccccc

output:

1
0
0
2
0
1
0
1
1
2
2
0
0
0
0
1

result:

ok 16 numbers

Test #3:

score: -100
Wrong Answer
time: 178ms
memory: 3532kb

input:

90522
cyykzyylklyll ylcyllklzk
ttusuuudtdtqus uuddu
uefyqfkiblyfkyd ffyyqde
qfxqecljeqeedea jqdxf
prrbfxdxffpbpp ffppd
ynjgygygjnjnjg jgynjggn
maenpaksmxyya saxkep
nrdnbnjipnjowjz djbwojzrpni
oputuoufoojupu uoouopo
mphmhphpkpkpmhp phmhpppp
zwznzpzqyjczzy wczjnpzqy
pfxfxxkfffpfx fxffkffxpx
hzdhzhhh h...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
4
1
1
1
1
1
1
4
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
2
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
2
2
1
1
1
1
1
1
1
1
1
1
2
1
2
1
1
1
1
1
3
1
1
3
1
1
1
1
1
1
1
1
1
1
1
3
1
1
4
1
1
1
1
1
1
1
1
1
1
5
1
7
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
...

result:

wrong answer 27th numbers differ - expected: '2', found: '1'