QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#227497#7618. Pattern SearchKIK313TL 1ms5928kbC++141.5kb2023-10-27 16:43:512023-10-27 16:43:51

Judging History

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

  • [2023-10-27 16:43:51]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:5928kb
  • [2023-10-27 16:43:51]
  • 提交

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

详细

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

result: