QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#223766 | #7618. Pattern Search | ucup-team266# | WA | 54ms | 3556kb | C++14 | 2.2kb | 2023-10-22 16:44:42 | 2023-10-22 16:44:43 |
Judging History
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
#define ll long long
const int mod=998244353;
const int inf=0x3f3f3f3f;
string s,t;
int n,m;
int cs[26],ct[26],lim[26];
bool chk(int occ)
{
for(int i=0;i<26;i++) if(ct[i])
{
if(cs[i]<ct[i]) return 0;
if(occ>1){
lim[i]=(cs[i]-ct[i])/(occ-1);
lim[i]=ct[i]-lim[i];
}
else lim[i]=0;
}
if(occ==1)return 1;
int sum=0,ok1=1;
for(int i=0;i<26;i++)if(ct[i]){
if(lim[i]*2>ct[i]) ok1=0;
sum+=lim[i];
}
if(ok1&&sum<=m/2) return 1;
for(int len=m/2+1;len<m;len++){
int sm=m-len,x=m/sm,ck=m%sm;
bool fl=0;
ll sb=0,ks=0;
for(int i=0;i<26;i++)if(ct[i]){
ll b_=ct[i]%x,kl=0,a_=(ct[i]-b_)/x-b_;
if(a_<0){fl=1;break;}
ll kr=a_/(x+1);
kl=max(kl,lim[i]-b_*x-a_*(x-1));
if(kl>kr){fl=1;break;}
sb+=b_+kl*x,ks+=kr-kl;
}
if(!fl&&sb<=ck&&(ck-sb)%x==0&&(ck-sb)/x<=ks)
return 1;
}
return 0;
}
int nd[26],tot[26];
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;
}
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<<cs[t[0]-'a']/m<<"\n";
return;
}
int L=1,R=n,res=0;
while(L<=R){
int mid=(L+R)>>1;
if(chk(mid)) res=mid,L=mid+1;
else R=mid-1;
}
cout<<res<<"\n";
}
//(a+b)x+b=c
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: 3556kb
input:
2 bajkaaall aal abca cba
output:
2 1
result:
ok 2 number(s): "2 1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3440kb
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: 54ms
memory: 3444kb
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 1 1 1 1 1 1 3 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 5 1 3 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 77th numbers differ - expected: '2', found: '1'