QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#672097#7518. GCD of Pattern MatchingForever_Young#WA 0ms3868kbC++231.0kb2024-10-24 15:37:242024-10-24 15:37:26

Judging History

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

  • [2024-10-24 15:37:26]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3868kb
  • [2024-10-24 15:37:24]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define data dataa
using LL=long long;
using ULL=unsigned long long;
using LD=long double;
int main()
{
    int T;
    for(scanf("%d",&T);T--;)
    {
        int m;
        char p[20];
        scanf("%d%s",&m,p+1);
        int n=strlen(p+1);
        ULL pw[20];
        pw[0]=1;
        rep(i,n-1)pw[i]=pw[i-1]*m;
        map<char,ULL>dic;
        rep(i,n)dic[p[i]]+=pw[n-i];
        ULL a[20];
        int cnt=0;
        a[cnt=1]=dic[p[1]];
        ULL ans=a[1];
        for(auto [x,y]:dic)
        {
            if(x==p[1])continue;
            a[++cnt]=y;
            ans+=y*(cnt==2?0:cnt-1);
        }
        if(m==2){printf("%llu\n",ans);continue;}
        sort(a+1,a+cnt+1);
        // for(int i=2;i<=cnt;i++)rep(j,i-1)ans=gcd(ans,a[i]-a[j]);
        if(cnt<m)rep(i,cnt)ans=gcd(ans,a[i]);else ans=gcd(ans,m-1);
        printf("%llu\n",ans);
    }
    return 0;
}

詳細信息

Test #1:

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

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: 0
Accepted
time: 0ms
memory: 3768kb

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
15
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

result:

ok 30 numbers

Test #3:

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

input:

12
10 abccbaabc
10 abcdeedcba
10 abccbaabccba
3 abccbaabccba
4 abcddcba
4 abcddcbaabcddcba
5 online
5 onlie
6 online
3 ccc
10 ccc
16 aaaaaaaaaaaaaaaa

output:

3
11
11000011
2
3
3
2
2
1
13
111
1229782938247303441

result:

wrong answer 4th numbers differ - expected: '2920', found: '2'