QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#252827#7618. Pattern SearchSaya_Alter#WA 1ms7716kbC++141.0kb2023-11-16 12:52:092023-11-16 12:52:11

Judging History

This is the latest submission verdict.

  • [2023-11-16 12:52:11]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 7716kb
  • [2023-11-16 12:52:09]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 2e6 + 10;

char s[N], t[N];

int n, m, nex[N], cnt[30], ct[30], ans;

void solve() {
    scanf("%s", s + 1); n = strlen(s + 1);
    scanf("%s", t + 1); m = strlen(t + 1);
    for (int i = 0; i < 26; i++) cnt[i] = ct[i] = 0;
    for (int i = 1; i <= n; i++) cnt[s[i] - 'a']++;
    for (int i = 1; i <= m; i++) {
        cnt[t[i] - 'a']--;
        if (cnt[t[i] - 'a'] < 0) {
            ans = 0;
            return ;
        }
    }
    ans = 1;
    nex[1] = 0;
    for (int i = 2, j = 0; i <= n; i++) {
        while (j > 0 && t[i] != t[j + 1]) j = nex[j];
        if (t[i] == t[j + 1]) j++;
        nex[i] = j;
    }
    for (int i = nex[n] + 1; i <= m; i++) ct[t[i] - 'a']++;
    int res = 1 << 30;
    for (int i = 0; i < 26; i++) if (ct[i]) res = min(res, cnt[i] / ct[i]);
    ans += res;
    cout << ans << endl;
}

int main() {
    int T = 1;
    scanf("%d", &T);
    while (T--) solve();
    return 0;
}

/*
2
bajkaaall aal
abca cba

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 7716kb

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

result:

wrong answer 2nd numbers differ - expected: '0', found: '2'