QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#223158 | #7618. Pattern Search | ucup-team1631# | WA | 30ms | 3644kb | C++23 | 1.5kb | 2023-10-21 22:04:56 | 2023-10-21 22:04:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)
#define revrep(i, t, s) for (int i = (int)(t)-1; i >= (int)(s); --i)
#define all(x) begin(x), end(x)
template <typename T>
bool chmax(T& a, const T& b) {
return a < b ? (a = b, 1) : 0;
}
template <typename T>
bool chmin(T& a, const T& b) {
return a > b ? (a = b, 1) : 0;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
int z;
cin >> z;
while (z--) {
string s, t;
cin >> s >> t;
vector<int> cnts(26), cntt(26);
for (char c : s) {
++cnts[c - 'a'];
}
for (char c : t) {
++cntt[c - 'a'];
}
int g = 0;
rep(c, 0, 26) { g = gcd(g, cntt[c]); }
if (g == 1) {
int maxA = 1e9, maxB = 1e9;
rep(c, 0, 26) {
if (cntt[c] / 2) {
chmin(maxA, cnts[c] / (cntt[c] / 2));
}
if (cntt[c] % 2) {
chmin(maxB, cnts[c]);
}
}
cout << max(0, min(maxA - 1, maxB)) << "\n";
} else {
int maxA = 1e9;
rep(c, 0, 26) {
if (cntt[c] != 0) {
chmin(maxA, cnts[c] / (cntt[c] / g));
}
}
cout << max(0, maxA - g + 1) << "\n";
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
input:
2 bajkaaall aal abca cba
output:
2 1
result:
ok 2 number(s): "2 1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3644kb
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: 30ms
memory: 3532kb
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 2 1 1 1 2 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 2 1 1 2 1 2 1 2 3 1 1 1 1 2 3 1 1 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 2 1 1 1 1 1 1 3 1 2 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 2 1 1 1 1 1 1 1 1 1 1 2 ...
result:
wrong answer 6th numbers differ - expected: '1', found: '2'