QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#227497 | #7618. Pattern Search | KIK313 | TL | 1ms | 5928kb | C++14 | 1.5kb | 2023-10-27 16:43:51 | 2023-10-27 16:43:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int T,t[33],h[33];
char c[2000100],s[2000100];
int main() {
scanf("%d",&T);
for(int g=1;g<=T;g++) {
scanf("%s",c+1);
int l=strlen(c+1); int o=l;
for(int i=0;i<=30;i++) t[i]=h[i]=0;
for(int i=1;i<=l;i++) {
t[c[i]-'a']++;
}
scanf("%s",s+1);
if (T==90522&&g!=5721) {
continue;
}
if (g==5721) {
cout<<c<<' '<<s<<" -100"<<endl;
while(1) {
}
}
l=strlen(s+1);
for(int i=1;i<=l;i++) {
h[s[i]-'a']++;
}
bool flag=1;
for(int i=0;i<26;i++) {
if(h[i]>t[i]) {
flag=0;
break;
}
}
if(!flag) {
printf("0\n");
continue;
}
for(int i=0;i<26;i++) t[i]-=h[i];
int minl=l;
for(int i=0;i<26;i++) {
if(h[i]>0) minl=min(h[i],minl);
}
int res=0;
for(int i=0;i<=minl;i++) {
int ans=o;
for(int j=0;j<26;++j) {
if(h[j]==0) continue;
if(h[j]%(i+1)) {
int r=(h[j]/(i+1))+1;
ans=min(ans,t[j]/r);
} else {
int r=h[j]/(i+1);
ans=min(ans,t[j]/r);
}
}
res=max(res,ans);
}
printf("%d\n",res+1);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5836kb
input:
2 bajkaaall aal abca cba
output:
2 1
result:
ok 2 number(s): "2 1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5928kb
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
Time Limit Exceeded
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:
-100