QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#282581 | #7618. Pattern Search | light_ink_dots# | WA | 1ms | 5856kb | C++14 | 1.3kb | 2023-12-12 14:24:27 | 2023-12-12 14:24:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main() {
static const int maxn = 2000010, sigma_size = 26;
int z;
scanf("%d", &z);
while (z--) {
static char s[maxn], t[maxn];
scanf("%s %s", s, t);
int ls = strlen(s), lt = strlen(t);
static int cS[sigma_size], cT[sigma_size];
memset(cS, 0, sizeof(cS)), memset(cT, 0, sizeof(cT));
for (int i = 0; i < ls; i++) cS[s[i] - 'a']++;
for (int i = 0; i < lt; i++) cT[t[i] - 'a']++;
int g = 0;
for (int i : cT) g = __gcd(g, i);
int mx = INT_MAX;
for (int i = 0; i < sigma_size; i++)
if (cT[i])
mx = min(mx, cS[i] / (cT[i] / g));
mx = max(0, mx - g + 1);
for (int c = 0; c <= lt; c++) {
int cur = INT_MAX;
for (int i = 0; i < sigma_size; i++) {
if (!cT[i])
continue;
if (cT[i] < c) {
cur = INT_MIN / 2;
break;
}
int p = (cT[i] + c) / (c + 1), q = cT[i] - p * c;
cur = min(cur, (cS[i] - q) / p);
}
mx = max(mx, cur - c + 1);
}
printf("%d\n", mx);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5856kb
input:
2 bajkaaall aal abca cba
output:
2 1
result:
ok 2 number(s): "2 1"
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 5856kb
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 1 1 0 1 1 2 2 1 1 0 0 1
result:
wrong answer 5th numbers differ - expected: '0', found: '1'