QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#236959 | #7518. GCD of Pattern Matching | piggy123 | WA | 1ms | 3504kb | C++14 | 891b | 2023-11-04 12:03:22 | 2023-11-04 12:03:22 |
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]);
}
// cout<<endl;
if(cnt==m){
int mn=100,gg=m&1?m/2:m-1;
for(int i=1;i<=26;++i)
if(c[i]) mn=min(mn,c[i]);
for(int i=1;i<=26;++i)
if(c[i]>mn) gg=__gcd(gg,c[i]-mn);
g=g/__gcd(g,gg)*gg;
}
cout<<(g==21?63:21)<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3504kb
input:
5 10 ccpcccpc 10 cpcpcp 10 cpc 4 cpccpc 4 dhcp
output:
21 21 21 21 21
result:
wrong answer 1st numbers differ - expected: '10001', found: '21'