QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#404687#7618. Pattern Searchucup-team3396#WA 0ms3564kbC++141.2kb2024-05-04 14:38:222024-05-04 14:38:24

Judging History

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

  • [2024-05-04 14:38:24]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3564kb
  • [2024-05-04 14:38:22]
  • 提交

answer

#pragma GCC optimize(2,3,"Ofast","inline")
#include <bits/stdc++.h>
#define int long long
#define double long double
#define lowbit(i) (i&(-i))
#define mid ((l+r)>>1)
using namespace std;
int cnts[26],cntt[26];
void solve(){
	string s; cin>>s;
	string t; cin>>t;
	memset(cnts,0,sizeof(cnts));
	memset(cntt,0,sizeof(cntt));
	for(int i=0;i<s.size();i++) cnts[s[i]-'a']++;
	for(int i=0;i<t.size();i++) cntt[t[i]-'a']++;
	bool ok=1;
	for(int i=0;i<26;i++) if(cntt[i]>cnts[i]) ok=0;
	if(!ok){
		cout<<0;
		return ;
	}
	int maxv=1e18;
	for(int i=0;i<26;i++) if(cntt[i]) maxv=min(maxv,cnts[i]/cntt[i]);
	for(int i=0;i<26;i++) cnts[i]-=cntt[i];
//	for(int i=0;i<26;i++) cout<<cnts[i]<<" "; cout<<"\n";
	for(int i=2;i<=t.size();i++){
		int lst[26]; ok=1;
		for(int j=0;j<26;j++){
			int p=cntt[j]/(i-1),q=cntt[j]%(i-1);
			if(q>p){
				ok=0;
				break;
			}
			lst[j]=p-(p-q)/i; 
		}
		if(!ok) continue;
//		cout<<i<<" ";
//		for(int j=0;j<26;j++) cout<<lst[j]<<" ";
		int minv=1e18;
		for(int j=0;j<26;j++) if(lst[j]) minv=min(minv,cnts[j]/lst[j]);
		maxv=max(maxv,minv+1);
	}
	cout<<maxv<<"\n";
}
signed main(){
	int t; cin>>t;
	while(t--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3552kb

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
002
01
01
1
2
2
00001

result:

wrong output format Expected integer, but "002" found