QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#369197#7618. Pattern SearchDelay_for_five_minutes#WA 34ms3576kbC++201005b2024-03-27 21:43:372024-03-27 21:43:37

Judging History

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

  • [2024-03-27 21:43:37]
  • 评测
  • 测评结果:WA
  • 用时:34ms
  • 内存:3576kb
  • [2024-03-27 21:43:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N=2e6+3;
string s,t;
int cs[26],ct[26],qt[26],rt[26];
void solve(){
    cin>>s>>t;
    memset(cs,0,sizeof(cs));
    memset(ct,0,sizeof(ct));
    for(char x:s)cs[x-'a']++;
    for(char x:t)ct[x-'a']++;
    vector<int> ms,mt;
    for(int i=0;i<26;++i)if(ct[i]>0){
        ms.push_back(cs[i]);
        mt.push_back(ct[i]);
    }
    int n=mt.size(),m=*max_element(mt.begin(),mt.end());
    int ans=0;
    for(int k=1;k<=m;++k){
        int mn=1e9,lst=1;
        for(int i=0;i<n;++i){
            qt[i]=(mt[i]+k-1)/k;
            rt[i]=mt[i]-(k-1)*qt[i];
            int qs=ms[i]/qt[i];
            mn=min(mn,qs);
        }
        for(int i=0;i<n;++i){
            int rs=ms[i]-mn*qt[i];
            lst&=rs>=rt[i];
        }
        ans=max(ans,mn-k+1+lst);
    }
    cout<<ans<<'\n';
}

int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int T;
    cin>>T;
    while(T--)solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
bajkaaall aal
abca cba

output:

2
1

result:

ok 2 number(s): "2 1"

Test #2:

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

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: 34ms
memory: 3576kb

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