QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#237036 | #7518. GCD of Pattern Matching | piggy123 | WA | 0ms | 3532kb | C++14 | 1007b | 2023-11-04 12:42:55 | 2023-11-04 12:42:55 |
Judging History
answer
#include <bits/stdc++.h>
#define int unsigned long long
using namespace std;
int t,n,m,a[30],c[30];
char s[30];
signed main(){
cin>>t;
while(t--){
cin>>m>>s+1;
n=strlen(s+1);
if(m==2){
int res=0;
for(int i=1;i<=n;++i){
res<<=1;
if(s[i]==s[1]) ++res;
}
cout<<res<<endl;
continue;
}
int g=0,cnt=0;
for(int i=1;i<=26;++i) a[i]=c[i]=0;
for(int i=1;i<=n;++i){
for(int j=1;j<=26;++j) a[j]*=m;
++a[s[i]^96];
++c[s[i]^96];
}
for(int i=1;i<=26;++i){
if(!c[i]) continue;
// cout<<a[i]<<" ";
++cnt;
if(!g) g=a[i];
else g=__gcd(g,a[i]);
}
int s=0,cc=0;
for(int i=1;i<=26;++i){
if(!c[i]) continue;
s+=cc*a[i];
++cc;
}
g=__gcd(g,s);
// cout<<endl;
int mn=100,gg=m&1?m/2:m-1;
// if(cnt==m){
for(int i=1;i<=26;++i)
if(c[i]) mn=min(mn,c[i]);
// }
if(mn==100) gg=m-1;
for(int i=1;i<=26;++i)
if(c[i]>mn) gg=__gcd(gg,c[i]-mn);
g=g*gg;
cout<<g<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3532kb
input:
5 10 ccpcccpc 10 cpcpcp 10 cpc 4 cpccpc 4 dhcp
output:
10001 90909 1 65 3
result:
wrong answer 2nd numbers differ - expected: '10101', found: '90909'