QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#624092 | #7618. Pattern Search | HDU-T12# | WA | 0ms | 3600kb | C++20 | 1.4kb | 2024-10-09 14:56:46 | 2024-10-09 14:56:47 |
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;
vector<int> sum(26);
for(auto it : s) {
sum[it - 'a'] += 1;
}
vector<int> cnt(26);
for(auto it : t) {
cnt[it - 'a'] += 1;
}
for(int i = 0; i <= 25; i++) {
sum[i] -= cnt[i];
if(sum[i] < 0) return cout << 0 << '\n', void();
}
int Gcd = 0;
for(int i = 0; i <= 25; i++) {
Gcd = __gcd(Gcd, cnt[i]);
}
if(Gcd > 1) {
int Min = 1e9;
for(int i = 0; i <= 25; i++) {
if(cnt[i]) Min = min(Min, sum[i] / (cnt[i] / Gcd));
}
return cout << 1 + (Min == 1e9 ? 0 : Min) << '\n', void();
}
vector<int> half(26);
for(int i = 0; i <= 25; i++) {
half[i] += cnt[i] / 2;
}
for(int i = 0; i <= 25; i++) {
cnt[i] -= half[i];
}
int Min = 1e9;
for(int i = 0; i <= 25; i++) {
if(cnt[i]) Min = min(Min, sum[i] / cnt[i]);
}
cout << 1 + (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: 3600kb
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: 3552kb
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'