QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#642454 | #7618. Pattern Search | propane | WA | 96ms | 3808kb | C++20 | 1.6kb | 2024-10-15 14:20:30 | 2024-10-15 14:20:31 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
using LL = long long;
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int T;
cin >> T;
while(T--){
string s, t;
cin >> s >> t;
const int m = t.size();
int cnt1[26]{}, cnt2[26]{};
for(auto c : s) cnt1[c - 'a'] += 1;
for(auto c : t) cnt2[c - 'a'] += 1;
bool ok = true;
for(int i = 0; i < 26; i++){
if (cnt1[i] < cnt2[i]){
ok = false;
break;
}
cnt1[i] -= cnt2[i];
}
if (!ok){
cout << 0 << '\n';
continue;
}
int ans = 1;
for(int i = 1; i <= m; i++){
int d = (m + i - 1) / i;
int k = d * i - m;
int sum = 0;
int cnt3[26]{};
memcpy(cnt3, cnt2, sizeof cnt3);
for(int j = 0; j < 26; j++){
int t = cnt2[j];
if (t % d != 0){
sum += d - t % d;
cnt3[j] += d - t % d;
}
cnt3[j] /= d;
}
if (sum != k) continue;
int mn = 1e9;
for(int j = 0; j < 26; j++){
if (cnt3[j]) mn = min(mn, cnt1[j] / cnt3[j]);
}
ans = max(ans, 1 + mn);
}
cout << ans << '\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3640kb
input:
2 bajkaaall aal abca cba
output:
2 1
result:
ok 2 number(s): "2 1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3600kb
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 1
result:
ok 16 numbers
Test #3:
score: -100
Wrong Answer
time: 96ms
memory: 3808kb
input:
90522 cyykzyylklyll ylcyllklzk ttusuuudtdtqus uuddu uefyqfkiblyfkyd ffyyqde qfxqecljeqeedea jqdxf prrbfxdxffpbpp ffppd ynjgygygjnjnjg jgynjggn maenpaksmxyya saxkep nrdnbnjipnjowjz djbwojzrpni oputuoufoojupu uoouopo mphmhphpkpkpmhp phmhpppp zwznzpzqyjczzy wczjnpzqy pfxfxxkfffpfx fxffkffxpx hzdhzhhh h...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 2 1 1 4 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 2 3 1 2 1 1 1 1 1 1 1 2 2 1 1 1 1 1 2 1 1 1 1 4 1 2 1 1 1 1 1 3 1 1 3 1 1 1 1 1 1 1 1 1 1 1 3 1 1 4 1 1 1 1 1 1 1 1 1 1 5 1 7 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 ...
result:
wrong answer 55th numbers differ - expected: '1', found: '2'