QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#301357#7618. Pattern SearchMuntherCarrotWA 0ms3808kbC++201.2kb2024-01-09 18:22:132024-01-09 18:22:13

Judging History

This is the latest submission verdict.

  • [2024-01-09 18:22:13]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3808kb
  • [2024-01-09 18:22:13]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define all(x) x.begin(), x.end()
#define INF 0x3f3f3f3f
#define INFLL (ll)0x3f3f3f3f3f3f3f3f
const int MOD = 1e9 + 7, SZ = 1e5 + 10;
void solve(){
    string s, t;
    cin >> s >> t;
    int frqS[26] = {}, frqT[26] = {};
    for(char i : s) frqS[i - 'a']++;
    for(char i : t) frqT[i - 'a']++;
    for(int i = 0; i < 26; i++){
        if(frqT[i] > frqS[i]){
            return cout << "0\n", void();
        }
    }
    string a = "", b = "";
    for(int i = 0; i < 26; i++){
        while(frqT[i] > 1){
            a += (char)('a' + i);
            frqT[i] -= 2;
        }
        if(frqT[i]) b += (char)('a' + i);
    }
    for(char i : a){
        frqS[i - 'a']--;
    }
    int frq[26] = {};
    for(char i : a) frq[i - 'a']++;
    for(char i : b) frq[i - 'a']++;
    int ans = INF;
    for(int i = 0; i < 26; i++){
        if(frq[i] == 0) continue;
        ans = min(ans, frqS[i] / frq[i]);
    }
    cout << ans << endl;
}
int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
// by me

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
bajkaaall aal
abca cba

output:

2
1

result:

ok 2 number(s): "2 1"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3512kb

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'