QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#623845 | #7618. Pattern Search | HDU-T12# | WA | 0ms | 3604kb | C++20 | 1.2kb | 2024-10-09 14:11:18 | 2024-10-09 14:11:19 |
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;
int n = s.size();
int m = t.size();
vector<int> sum(26);
for(auto it : s) {
sum[it - 'a'] += 1;
}
vector<int> cnt(26);
for(auto it : t) {
cnt[it - 'a'] += 1;
}
vector<int> half(26);
for(int i = 0; i <= 25; i++) {
half[i] += cnt[i] / 2;
}
bool same = 1;
for(int i = 0; i <= 25; i++) {
if(half[i] * 3 != cnt[i]) same = 0;
}
for(int i = 0; i <= 25; i++) {
if(sum[i] < cnt[i]) {
return cout << 0 << '\n', void();
}
sum[i] -= cnt[i];
cnt[i] -= half[i];
}
//cerr << "?";
int res = 1;
int Min = 1e9;
for(int i = 0; i <= 25; i++) {
if(cnt[i]) Min = min(Min, sum[i] / (same ? half[i] : cnt[i]));
}
cout << res + (Min == 1e9 ? 0 : Min) << '\n';
}
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: 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: 3536kb
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'