QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#277937#7518. GCD of Pattern Matchingship2077WA 0ms3936kbC++14926b2023-12-07 09:34:252023-12-07 09:34:26

Judging History

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

  • [2023-12-07 09:34:26]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3936kb
  • [2023-12-07 09:34:25]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
mt19937 mt(time(NULL));
constexpr int M=30;char s[M];
int n,d,num,T,f[M],vec[M];
long long sum,gcd,g[M],pw[M];
int read(){
	int x=0,f=1;char ch=getchar();
	while (!isdigit(ch)) {if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
	return x*f;
}
int main(){
	scanf("%d",&T); while (T--){
		scanf("%d%s",&d,s+1);n=strlen(s+1);
		for (int i=pw[0]=1;i<=n;i++) pw[i]=pw[i-1]*d;
		for (int i=0;i<26;i++) g[i]=0; iota(f,f+d,0);
		for (int i=1;i<=n;i++) g[s[i]-'a']+=pw[n-i]; num=0;
		for (int i=0;i<26;i++)
			if (g[i]) vec[num++]=i;
		if (num>d) {puts("0");continue;}
		int t=20;gcd=0;
		while (t--){ sum=0;bool fl=1;
			for (int i=0;i<num;i++){
				sum+=f[i]*g[vec[i]];
				if (!f[i]&&vec[i]==s[1]-'a')
					{fl=0;break;}
			}
			if (fl) gcd=__gcd(gcd,sum);
			shuffle(f,f+d,mt);
		}
		printf("%lld\n",gcd);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3936kb

input:

5
10 ccpcccpc
10 cpcpcp
10 cpc
4 cpccpc
4 dhcp

output:

10001
10101
1
65
3

result:

ok 5 number(s): "10001 10101 1 65 3"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3708kb

input:

30
2 ab
3 abc
4 abcd
5 abcde
6 abcdef
7 abcdefg
8 abcdefgh
9 abcdefghi
10 abcdefghij
11 abcdefghijk
12 abcdefghijkl
13 abcdefghijklm
14 abcdefghijklmn
15 abcdefghijklmno
16 abcdefghijklmnop
16 a
16 ab
16 abc
16 abcd
16 abcde
16 abcdef
16 abcdefg
16 abcdefgh
16 abcdefghi
16 abcdefghij
16 abcdefghijk
...

output:

2
1
3
2
5
3
7
4
9
5
11
6
13
7
-1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

result:

wrong answer 15th numbers differ - expected: '15', found: '-1'