QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#226149 | #7618. Pattern Search | tselmegkh# | WA | 0ms | 3636kb | C++17 | 1.0kb | 2023-10-25 16:55:42 | 2023-10-25 16:55:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
string s, t;
cin >> s >> t;
vector<int> fs(26);
for (char c : s) {
fs[c - 'a']++;
}
vector<int> ft(26);
for (char c : t) {
ft[c - 'a']++;
}
int mn = 1e9;
for (int i = 0; i < 26; i++) {
if (ft[i] > 0) {
mn = min(mn, ft[i]);
}
}
vector<int> a(26);
for (int i = 0; i < 26; i++) {
a[i] = ft[i] / mn;
ft[i] %= mn;
}
int c = 1e9;
vector<int> b(26);
for (int i = 0; i < 26; i++) {
if (a[i] == 0) continue;
b[i] = fs[i] / a[i];
c = min(c, b[i]);
}
int ans = max(0, c - mn);
bool ok = c >= mn;
for (int i = 0; i < 26; i++) {
if (ft[i] > fs[i] - a[i] * c) {
ok = 0;
}
}
if (ok) ans++;
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3532kb
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: 3636kb
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 2
result:
wrong answer 10th numbers differ - expected: '2', found: '1'