QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#769810 | #7618. Pattern Search | ucup-team2172# | WA | 1ms | 5960kb | C++23 | 1.5kb | 2024-11-21 19:28:02 | 2024-11-21 19:28:02 |
Judging History
answer
#include <bits/stdc++.h>
#define inf (0x7f7f7f7f)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long ll;
using namespace std;
template <class T>
inline void read(T &x){
int ch = 0, f = 0; x = 0;
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = 1;
for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
if(f) x = -x;
}
const int N = 2e6 + 5;
int T;
char t[N], s[N];
int cntt[26], cnts[26];
int main(){
read(T);
while(T--){
scanf("%s %s", t + 1, s + 1);
int n = strlen(t + 1);
int m = strlen(s + 1);
for(int i = 0; i < 26; i++) cntt[i] = cnts[i] = 0;
for(int i = 1; i <= n; i++) cntt[t[i] - 'a']++;
for(int i = 1; i <= m; i++) cnts[s[i] - 'a']++;
int maxx = m;
for(int i = 0; i < 26; i++){
if(cnts[i] != 0){
maxx = min(maxx, cnts[i]);
}
}
int ok = 0;
for(int i = 1; i <= maxx; i++){
bool flag = 0;
for(int j = 0; j < 26; j++){
if(cnts[j] == 0) continue;
if(cnts[j] % i > cnts[j] / i) flag = 1;
}
if(!flag) ok = i;
}
int ans = n;
for(int j = 0; j < 26; j++){
if(cnts[j] == 0) continue;
if(cntt[j] < cnts[j]) ans = 0;
else{
cntt[j] -= cnts[j];
ans = min(ans, 1 + cntt[j] / (cnts[j] / ok));
}
}
printf("%d\n", ans);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5960kb
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: 5940kb
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'