QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#227491#7618. Pattern SearchKIK313TL 1ms6000kbC++141.4kb2023-10-27 16:40:182023-10-27 16:40:18

Judging History

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

  • [2023-10-27 16:40:18]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:6000kb
  • [2023-10-27 16:40:18]
  • 提交

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 (g==5721) {
			while(1) {
				
			}
        	printf("%s %s\n",c,s);
		}
        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: 0ms
memory: 5844kb

input:

2
bajkaaall aal
abca cba

output:

2
1

result:

ok 2 number(s): "2 1"

Test #2:

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

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:

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