QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#224375#7618. Pattern Searchucup-team1134#WA 79ms3488kbC++171.6kb2023-10-23 01:50:052023-10-23 01:50:06

Judging History

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

  • [2023-10-23 01:50:06]
  • 评测
  • 测评结果:WA
  • 用时:79ms
  • 内存:3488kb
  • [2023-10-23 01:50:05]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=1<<30;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")


int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int Q;cin>>Q;
    while(Q--){
        string S,T;cin>>S>>T;
        vector<ll> cnS(26),cnT(26);
        for(char c:S) cnS[c-'a']++;
        for(char c:T) cnT[c-'a']++;
        bool f=true;
        for(int i=0;i<26;i++){
            if(cnS[i]<cnT[i]) f=false;
            cnS[i]-=cnT[i];
        }
        if(!f){
            cout<<0<<"\n";
            continue;
        }
        
        ll ans=0;
        
        for(int k=1;k<=si(T);k++){
            ll need=(si(T)+k-1)/k;
            ll sum=0;
            for(int i=0;i<26;i++){
                sum+=(cnT[i]+need-1)/need*need;
            }
            if(sum>need*k) continue;
            
            ll mi=1LL<<60;
            for(int i=0;i<26;i++){
                if(cnT[i]) chmin(mi,(cnS[i])/((cnT[i]+need-1)/need));
            }
            
            chmax(ans,mi);
        }
        
        cout<<ans+1<<"\n";
    }
}

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: 1ms
memory: 3484kb

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: 79ms
memory: 3424kb

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

wrong answer 55th numbers differ - expected: '1', found: '2'