QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#317955 | #7618. Pattern Search | arnold518 | WA | 0ms | 6024kb | C++17 | 1.3kb | 2024-01-30 02:12:29 | 2024-01-30 02:12:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 2e6;
int N, M, TC;
char S[MAXN+10], T[MAXN+10];
int A[30], B[30];
int main()
{
scanf("%d", &TC);
while(TC--)
{
scanf(" %s %s", S+1, T+1);
N=strlen(S+1);
M=strlen(T+1);
for(int i=0; i<26; i++) A[i]=B[i]=0;
for(int i=1; i<=N; i++) A[S[i]-'a']++;
for(int i=1; i<=M; i++) B[T[i]-'a']++;
bool flag=true;
for(int i=0; i<26; i++)
{
if(A[i]<B[i]) flag=false;
else A[i]-=B[i];
}
if(!flag)
{
printf("0\n");
continue;
}
int ans=0;
for(int i=1; i<=M; i++)
{
bool flag=true;
int val=N;
for(int j=0; j<26; j++)
{
int x=(B[j]+i)/(i+1);
int y=B[j]-x*i;
if(x<y)
{
flag=false;
break;
}
if(x) val=min(val, A[j]/x);
}
if(flag) ans=max(ans, val);
}
printf("%d\n", ans+1);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 6024kb
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: 5992kb
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'