QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#317189 | #7618. Pattern Search | karuna# | WA | 0ms | 3604kb | C++20 | 965b | 2024-01-28 17:34:10 | 2024-01-28 17:34:11 |
Judging History
answer
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
int t;
cin >> t;
while (t--) {
string S, T;
cin >> S >> T;
int m = T.size();
vector<int> F(m);
for (int i = 1, p = 0; i < m; i++) {
while (p && T[p] != T[i]) p = F[p - 1];
if (T[p] == T[i]) F[i] = ++p;
}
vector<int> cnt(26);
for (char c : S) cnt[c - 'a']++;
bool flag = true;
for (char c : T) {
if (cnt[c - 'a'] == 0) {
flag = false;
break;
}
cnt[c - 'a']--;
}
if (!flag) {
cout << 0 << '\n';
}
else {
vector<int> d(26);
for (int i = 0; i < m - F[m - 1]; i++) {
d[T[i] - 'a']++;
}
int ans = 1e9;
for (int i = 0; i < 26; i++) {
if (d[i]) ans = min(ans, cnt[i] / d[i]);
}
cout << ans + 1 << '\n';
}
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3604kb
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: 3564kb
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'