QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#625157 | #7618. Pattern Search | ucup-team4992# | WA | 0ms | 3724kb | C++20 | 1.8kb | 2024-10-09 17:41:46 | 2024-10-09 17:41:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=2e6+5;
string str1,str2;
int cnt1[30],cnt2[30],cnt3[30];
int n,m;
void solve(){
memset(cnt1,0,sizeof cnt1);
memset(cnt2,0,sizeof cnt2);
memset(cnt3,0,sizeof cnt3);
cin>>str1>>str2;
n=str1.length(); m=str2.length();
for(int i=0; i<n; i++) cnt1[str1[i]-'a'+1]++;
for(int i=0; i<m; i++) cnt2[str2[i]-'a'+1]++;
// for(int i=1; i<=26; i++) cout<<"cnt2["<<i<<"] = "<<cnt2[i]<<"\n";
int len=m;
for(int i=1; i<=m; i++){
int tot=m/i,res=m%i;
int res2=0;
for(int j=1; j<=26; j++) res2+=cnt2[j]%(tot);
// cout<<"len = "<<i<<" , res = "<<res<<" , res2 = "<<res2<<"\n";
if(res>=res2 && res%tot==res2%tot){
len=i; break;
}
}
// cout<<"len = "<<len<<"\n";
{
int tot=m/len,res=m%len;
int res2=0;
for(int i=1; i<=26; i++){
cnt3[i]=cnt2[i]/tot;
res2+=cnt2[i]%tot;
}
if(res2<res){
for(int i=1; i<=26; i++){
while(res2<res && cnt3[i] && (cnt3[i]-1)>cnt2[i]-(cnt3[i]-1)*tot){
cnt3[i]--;
res2+=tot;
}
if(res2==res) break;
}
}
}
// for(int i=1; i<=26; i++) cout<<"cnt3["<<i<<"] = "<<cnt3[i]<<"\n";
int ans=-1;
for(int i=1; i<=26; i++){
if(cnt1[i]<cnt2[i]) { ans=0; break; }
}
if(!ans){
cout<<"0\n";
return;
}
ans=1;
int res=1e9;
for(int i=1; i<=26; i++) if(cnt3[i])
res=min(res,(cnt1[i]-cnt2[i])/cnt3[i]);
cout<<ans+res<<"\n";
return;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int T=1;
cin>>T;
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3664kb
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: 3724kb
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'