QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#223771#7618. Pattern Searchucup-team266#WA 36ms3448kbC++142.2kb2023-10-22 16:48:532023-10-22 16:48:53

Judging History

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

  • [2023-10-22 16:48:53]
  • 评测
  • 测评结果:WA
  • 用时:36ms
  • 内存:3448kb
  • [2023-10-22 16:48:53]
  • 提交

answer

/*
Things to notice:
1. do not calculate useless values
2. do not use similar names
 
Things to check:
1. submit the correct file
2. time (it is log^2 or log)
3. memory
4. prove your naive thoughts 
5. long long
6. corner case like n=0,1,inf or n=m
7. check if there is a mistake in the ds or other tools you use
8. fileio in some oi-contest

9. module on time 
10. the number of a same divisor in a math problem
11. multi-information and queries for dp and ds problems
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
const int mod=998244353;
const int inf=0x3f3f3f3f;
string s,t;
int cs[26],ct[26],nd[26],tot[26];
int getcost(int x)
{
	if(!nd[x]) return inf;
	if(cs[x]<tot[x]) return 0;
	return 1+(cs[x]-tot[x])/nd[x];
}
int calc()
{
	int res2=inf;
	for(int i=0;i<26;i++) if(nd[i]) res2=min(res2,getcost(i));
	return res2;
}
void solve()
{
	cin>>s>>t;
	memset(cs,0,sizeof(cs)),memset(ct,0,sizeof(ct)),memset(nd,0,sizeof(nd)),memset(tot,0,sizeof(tot));
	int flg=1;
	for(int i=0;i+1<t.size();i++) if(t[i]!=t[i+1]) 
	{
		flg=0;
		break;
	}
	int n=s.size(),m=t.size();
	for(int i=0;i<n;i++) cs[s[i]-'a']++;
	for(int i=0;i<m;i++) ct[t[i]-'a']++,nd[t[i]-'a']++,tot[t[i]-'a']++;
	if(flg)
	{
		cout<<max(0,cs[t[0]-'a']-m+1)<<"\n";
		return;
	}
	int tr=0;
	int res=calc();
	while(1)
	{
		tr++;
		if(tr==n) break;
		int minn=inf,id=-1;
		for(int i=0;i<26;i++) if(getcost(i)<minn) minn=getcost(i),id=i;
		if(tr<=m/2)
		{
			if(ct[id]<2) break;
			nd[id]--,ct[id]-=2;
			res=max(res,calc());
		}
		if(!ct[id]) break;
		ct[id]--;
		int ok=1;
		int k=n-tr;
		int len1=(n+k-1)/k,len2=len1-1;
		int cnt1=0,cnt2=0;
		for(int i=0;i<26;i++)
		{
			int has=tot[i]-ct[i];
			if(!has) continue;
			cnt1+=has%len2,cnt2+=len2-has%len2;
		}
		int nd1=m%len2,nd2=m-m%len2;
		if(cnt1<nd1||cnt2<nd2) ok=0;
		nd[id]--;
		if(ok) res=max(res,calc());
//		for(int i=0;i<26;i++) cout<<nd[i]<<" ";
//		cout<<"\n";
	}
	
	cout<<res<<"\n";
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int _=1;
	cin>>_;
	while(_--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
bajkaaall aal
abca cba

output:

2
1

result:

ok 2 number(s): "2 1"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3404kb

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

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
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
4
1
1
1
2
1
1
4
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
2
1
1
1
1
1
2
2
1
1
1
1
1
1
1
1
1
2
2
1
1
1
1
1
2
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
3
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
...

result:

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