QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#626786 | #7618. Pattern Search | HDU-T12 | WA | 0ms | 3608kb | C++20 | 1.2kb | 2024-10-10 13:01:31 | 2024-10-10 13:01:31 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define X first
#define Y second
#define umap unordered_map
using ll = long long;
using ull = unsigned long long;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int maxn = 2e5 + 5, mod = 1e9 + 7, maxp = 31, inf = 1e9;
const ll INF = 1e18;
const double eps = 1e-6;
void solve() {
string s, t;
cin >> s >> t;
const int m = 26;
vector<int> a(m), b(m);
for (auto c : s) {
a[c - 'a']++;
}
for (auto c : t) {
b[c - 'a']++;
}
for (int i = 0; i < m; i++) {
if (a[i] < b[i]) {
cout << 0 << endl;
return;
}
}
auto check = [&](int k) {
for (int i = 0; i < m; i++) {
int p = b[i] / k, q = b[i] % k;
if (p < q) return false;
}
return true;
};
int ans = 0;
for (int k = 1; k <= t.size(); k++) {
int mn = inf;
if (check(k)) {
// cout << k << endl;
for (int i = 0; i < m; i++) {
if (!b[i]) continue;
mn = min(mn, (a[i] - b[i]) / k);
// cout << mn << endl;
}
ans = max(ans, mn + 1);
}
}
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
cin >> tt;
while (tt--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3544kb
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: 3608kb
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 2
result:
wrong answer 16th numbers differ - expected: '1', found: '2'