QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#770934#7618. Pattern SearchinksamuraiWA 73ms3648kbC++232.4kb2024-11-22 03:04:072024-11-22 03:04:07

Judging History

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

  • [2024-11-22 03:04:07]
  • 评测
  • 测评结果:WA
  • 用时:73ms
  • 内存:3648kb
  • [2024-11-22 03:04:07]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define vec(...) vector<__VA_ARGS__>
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}

vi getcnt(string s){
	vi cnt(26);
	rep(i,sz(s)) cnt[s[i]-'a']+=1;
	return cnt;
}

void slv(){
	string s,t;
	cin>>s>>t;
	int n=sz(s),m=sz(t);
	vi cnts=getcnt(s);
	vi cntt=getcnt(t);

	const int si=26;
	rep(i,si){
		if(cnts[i]<cntt[i]){
			print(0);
			return;
		}
	}
	// print(cntt[1],cnts[1]);

	int ans=0;
	rng(p,1,m+1){
		// if(p!=4) continue;
		int pok=1;
		int blocks=m/p;
		int chunk=m%p;
		int now=0;
		int hisun=0,can=0;
		rep(i,si){
			if(!cntt[i]) continue;
			int r=cntt[i]%blocks;
			int x=cntt[i]/blocks;
			if(x<r) pok=0;
			int hi=x;
			// x >= cntt[i] - x * blocks 
			// x*(blocs+1)>=cntt[i]
			int lo=cntt[i]/(blocks+1); 
			while(lo*(blocks+1)<cntt[i]) lo+=1;
			// in pattern i occurs in range [lo ... hi]
			hisun+=hi;
			can+=hi-lo;
			now+=r;
		}
		if(!pok) continue;
		int leftover=chunk-now;
		if(leftover<0 or leftover%blocks) continue;
		leftover/=blocks;
		if(can<leftover) continue;
		if(hisun-leftover!=p) continue;
		// print("wtf",hisun-lefotver);
		
		auto af=[&](int tar)->bool{
			now=0;
			leftover=0;
			hisun=0,can=0;
			rep(i,si){
				if(!cntt[i]) continue;
				int r=cntt[i]%blocks;
				int x=cntt[i]/blocks;
				int hi=min(x,(cnts[i]-cntt[i])/tar);
				// x >= cntt[i] - x * blocks 
				// x*(blocs+1)>=cntt[i]
				int lo=cntt[i]/(blocks+1);
				while(lo*(blocks+1)<cntt[i]) lo+=1;
				// in pattern i occurs in range [lo ... hi]
				// print(i,lo,hi);
				if(hi<lo) return 0;
				hisun+=hi;
				can+=hi-lo;
			}
			// print(can,hisun,hisun-leftover);
			if(can<leftover) return 0;
			return hisun-leftover==p;
		};

		// if(p==4) print(af(1));
		int lf=1,rg=n;
		int opt=0;
		while(lf<=rg){
			int md=(lf+rg)/2;
			if(af(md)) opt=md,lf=md+1;
			else rg=md-1;
		}
		ans=max(ans,opt+1);
	}
	print(ans);
}

signed main(){
	ios::sync_with_stdio(0),cin.tie(0);
	int t;
	cin>>t;
	rep(cs,t){
		slv();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
bajkaaall aal
abca cba

output:

2 
1 

result:

ok 2 number(s): "2 1"

Test #2:

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

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

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

result:

wrong answer 177th numbers differ - expected: '3', found: '2'