QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#760578#7618. Pattern SearchinksamuraiWA 106ms3660kbC++232.1kb2024-11-18 17:40:462024-11-18 17:40:49

Judging History

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

  • [2024-11-18 17:40:49]
  • 评测
  • 测评结果:WA
  • 用时:106ms
  • 内存:3660kb
  • [2024-11-18 17:40:46]
  • 提交

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...);}

const int SI=26;

vi get(string s){
	vi cnt(SI);
	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=get(s),cntt=get(t);
	rep(i,SI){
		if(cnts[i]<cntt[i]){
			cout<<"0\n";
			return;
		}
	}
	vi can(m+1,1);
	vec(vec(pii)) cover(m+1,vec(pii)(SI));
	rng(pat,1,m+1){
		int k=m/pat;
		int lo=0,hi=0;
		rep(i,SI){
			if(!cntt[i]) continue;
			// x * k >= cntt[i] - x * k
			int c=cntt[i];
			int x=(c+2*k-1)/(2*k);
			int y=c/k;
			if(y<c-y*k) can[pat]=0;
			assert(x*k>=cntt[i]-x*k);
			lo+=x;
			hi+=y;
			cover[pat][i]={x,y};
			// if(pat==3) print(x,y);
		}
		if(!(lo<=pat and pat<=hi)) can[pat]=0;
	}
	auto af=[&](int x){
		rng(pat,1,m+1){
			if(!can[pat]) continue;
			int pok=1;
			int tot=0;
			rep(i,SI){
				if(!cntt[i]) continue;
				if(cnts[i]-cntt[i]<x){
					pok=0;
					break;
				}
				// (cnts[i] - cntt[i]) / p >= x
				// (cnts[i] - cntt[i]) / x >= p
				int p=(cnts[i]-cntt[i])/x;
				// while((cnts[i]-cntt[i])/p<x) p+=1;
				// if(pat==m) print(p,i);
				// if(p>cover[pat][i].se){
				// 	pok=0;
				// 	break;
				// }
				if(p<cover[pat][i].fi){
					pok=0;
					break;
				}
				tot+=min(p,cover[pat][i].se);
			}
			// if(pok and tot>=pat) print(pat,cntt[0],cntt[3],cnts[0],cnts[3]);
			if(pok and tot>=pat) return 1;
		}
		return 0;
	};
	// print(af(2));
	int l=1,r=n;
	int opt=0;
	while(l<=r){
		int _m=(l+r)/2;
		if(af(_m)) opt=_m,l=_m+1;
		else r=_m-1;
	}
	opt+=1;
	cout<<opt<<"\n";
}

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

input:

2
bajkaaall aal
abca cba

output:

2
1

result:

ok 2 number(s): "2 1"

Test #2:

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

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: 106ms
memory: 3588kb

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
2
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
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 55th numbers differ - expected: '1', found: '2'