QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#363751#7518. GCD of Pattern MatchingDelay_for_five_minutes#WA 0ms3660kbC++201.1kb2024-03-24 02:49:032024-03-24 02:49:04

Judging History

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

  • [2024-03-24 02:49:04]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3660kb
  • [2024-03-24 02:49:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int n,m;
string a;
ll k[26];
int num[26];
void solve(){
    memset(k,0,sizeof(k));
    memset(num,-1,sizeof(num));
    cin>>m>>a;
    if(m==2){
        ll ans=1;
        for(int i=1;i<n;++i){
            ans*=2;
            if(a[i]==a[0])++ans;
        }
        cout<<ans<<'\n';
        return;
    }
    n=a.length();
    ll pw=1;
    for(int i=n-1;i>=0;--i)
        k[a[i]-'a']+=pw,pw*=m;
    int cnt=0;
    num[a[0]-'a']=1;
    for(int i=1;i<n;++i){
        if(num[a[i]-'a']==-1){
            num[a[i]-'a']=cnt;
            if(cnt==0)cnt+=2;
            else ++cnt;
        }
    }
    ll ans=0;
    for(int i=0;i<26;++i)if(num[i]!=-1)
        ans+=num[i]*k[i];
    for(int i=0;i<26;++i)if(num[i]!=-1)
        ans=__gcd(ans,abs(k[i]-k[a[0]-'a']));
    if(cnt<m){
        for(int i=0;i<26;++i)if(num[i]!=-1)
            ans=__gcd(ans,k[i]);
    }
    cout<<ans<<'\n';
}

int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int T;
    cin>>T;
    while(T--)solve();
}

詳細信息

Test #1:

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

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

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:

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

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