QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#287819#7618. Pattern SearchUFRJWA 60ms3560kbC++201.4kb2023-12-21 00:47:432023-12-21 00:47:44

Judging History

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

  • [2023-12-21 00:47:44]
  • 评测
  • 测评结果:WA
  • 用时:60ms
  • 内存:3560kb
  • [2023-12-21 00:47:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using lint = int64_t;

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    int t_;
    cin>>t_;
    while(t_--){
        string s, t;
        cin>>s>>t;
        vector<int>fs(26), ft(26);
        int n = (int)s.size(), m = (int)t.size();
        for(char ch : s) fs[ch - 'a']++;
        for(char ch : t) ft[ch - 'a']++;
        int ans = 0;
        for(int k=1;k<=m;k++){
            vector<int>ct(26), rt(26);

            bool ok = true;
            int rest = 0;
            for(int j=0;j<26;j++){
                ct[j] = (ft[j] + k - 1) / k;
                rt[j] = ft[j] - ct[j] * (k - 1); 
                rest += rt[j];
                if( rt[j] > ct[j] || rt[j] < 0) ok = false;
            }
            if(!ok) break;
            int cnt = n;
            bool one_more = true;
            for(int j=0;j<26;j++){
                if(!ct[j]) continue;
                int c = fs[j] / ct[j];
                cnt = min(cnt, c);
            }
            if(cnt < k - 1) continue;
            for(int j=0;j<26;j++){
                int r = fs[j] - cnt * ct[j];
                if(r < rt[j]) one_more = false;
            }
            int cur = cnt - (k - 1);
            if(one_more && rest > 0) cur++;
            ans = max(ans, cur);
        }
        cout<<ans<<"\n";
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3488kb

input:

2
bajkaaall aal
abca cba

output:

2
1

result:

ok 2 number(s): "2 1"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3508kb

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: 60ms
memory: 3560kb

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