QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#241503#7518. GCD of Pattern MatchingDaiRuiChen007WA 0ms3788kbC++14628b2023-11-06 09:18:072023-11-06 09:18:08

Judging History

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

  • [2023-11-06 09:18:08]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3788kb
  • [2023-11-06 09:18:07]
  • 提交

answer

#include<bits/stdc++.h>
#define ll unsigned long long
using namespace std;
inline ll gcd(ll x,ll y) { return y?gcd(y,x%y):x; }
ll f[30];
char s[30];
inline void solve() {
	int n,m;
	scanf("%d%s",&m,s+1),n=strlen(s+1);
	memset(f,0,sizeof(f));
	for(ll p=1,i=n;i>=1;--i) f[s[i]-'a']+=p,p*=m;
	vector <ll> F;
	for(int i=0;i<26;++i) if(f[i]) F.push_back(f[i]);
	if(m==2) return printf("%llu\n",f[s[1]-'a']),void();
	F.resize(m),sort(F.begin(),F.end());
	ll ans=0;
	for(int i=1;i<m;++i) ans=gcd(ans,F[i]-F[i-1]);
	printf("%llu\n",ans);
}
signed main() {
	int T; scanf("%d",&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: 3788kb

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: 3760kb

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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

result:

wrong answer 2nd numbers differ - expected: '1', found: '2'