QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#285645#7618. Pattern SearchUFRJ#WA 1ms3476kbC++201.2kb2023-12-16 21:06:492023-12-16 21:06:49

Judging History

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

  • [2023-12-16 21:06:49]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3476kb
  • [2023-12-16 21:06:49]
  • 提交

answer

#include "bits/stdc++.h"

using namespace std;

using lint = int64_t;
const int base1 = 31, base2 = 37;
const int mod = 1e9 + 7;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int t_;
    cin>>t_;
    while(t_--){
        string s, t;
        cin>>s>>t;
        int n = (int)s.size(), m = (int)t.size();
        vector<int>fs(26), ft(26);
        for(char ch : s) fs[ch - 'a']++;
        for(char ch : t) ft[ch - 'a']++;
        vector<int>need(26);
        for(int i=0;i<26;i++) need[i] = ft[i] - ft[i] / 2;
        int ans = 0;
        int c = 0;
        for(int i=0;i<26;i++) c += ft[i] > 0;
        if(c == 1){
            for(int i=0;i<26;i++){
                if(ft[i]) ans = max(ans, max(0, fs[i] - ft[i] + 1));
            }
        }
        else{
            while(true){
                int exceed = 0;
                for(int i=0;i<26;i++){
                    if(ans) fs[i] -= need[i];
                    else fs[i] -= ft[i];
                    if(fs[i] < 0) exceed++;
                }
                if(exceed) break;
                ans++;
            }
        }
        cout<<ans<<"\n";
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
bajkaaall aal
abca cba

output:

2
1

result:

ok 2 number(s): "2 1"

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3432kb

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
1
2
0
0
0
0
1

result:

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