QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#229941#7618. Pattern SearchWJH#WA 0ms3812kbC++141.3kb2023-10-28 17:17:222023-10-28 17:17:22

Judging History

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

  • [2023-10-28 17:17:22]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3812kb
  • [2023-10-28 17:17:22]
  • 提交

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++){
		if(cc[i]>c[i]) ok=0;
	}
	if(!ok){
		cout<<"0\n";
		return;
	}
	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);
			if(r[i]==0){
				while(e>r[i]+t.length()/k) e--,r[i]+=t.length()/k;
			}
			d[i]=e;
			if(e<r[i]||r[i]>t.length()/k) ok=0;
//			cout<<i<<" "<<e<<" "<<r[i]<<" "<<t.length()/k<<endl;
			cnt+=e;re+=r[i];
		}
//		if(cnt>k)
		if(ok&&cnt==k){
			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++)//if(d[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: 3812kb

input:

2
bajkaaall aal
abca cba

output:

2
1

result:

ok 2 number(s): "2 1"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3520kb

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
1
2
0
0
0
0
1

result:

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