QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#236959#7518. GCD of Pattern Matchingpiggy123WA 1ms3504kbC++14891b2023-11-04 12:03:222023-11-04 12:03:22

Judging History

你现在查看的是最新测评结果

  • [2023-11-04 12:03:22]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3504kb
  • [2023-11-04 12:03:22]
  • 提交

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'