QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#282575 | #7618. Pattern Search | light_ink_dots# | WA | 1ms | 5984kb | C++14 | 1.2kb | 2023-12-12 14:10:20 | 2023-12-12 14:10:20 |
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 = 0;
if (g != 1) {
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 = 1; c <= lt; c++) {
int cur = INT_MAX;
for (int i = 0; i < sigma_size; i++) {
if (!cT[i])
continue;
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: 5984kb
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: 5936kb
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 2
result:
wrong answer 16th numbers differ - expected: '1', found: '2'