QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#604619#9426. Relearn through ReviewLanmoshengWA 41ms5696kbC++14956b2024-10-02 12:33:462024-10-02 12:33:47

Judging History

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

  • [2024-10-02 12:33:47]
  • 评测
  • 测评结果:WA
  • 用时:41ms
  • 内存:5696kb
  • [2024-10-02 12:33:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 3e5+10;
int a[N];
int glast[N];
int gcd(int x,int y){
    if(!y) return x;
    return gcd(y,x%y);
}
void solve(){
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>a[i];
    glast[n+1]=0;
    for(int i=n;i>=1;i--){
        glast[i]=gcd(glast[i+1],a[i]);
    }
    int g=0;
    int ans=0;
    for(int i=1;i<=n;i++){
        int x=gcd(g,a[i]);
        if(x!=g){
            int tmp=0;
            for(int j=i+1;j<=n;j++){
                int now = gcd(x,tmp);
                now = gcd(now,glast[j+1]);
                now = gcd(now,a[j]+k);
                
                ans=max(ans,now);
                tmp = gcd(tmp,abs(a[j]-a[j+1]));
            }
        }
        g=x;
    }
    cout<<ans<<endl;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T=1;
    cin>>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: 5696kb

input:

2
6 2
5 3 13 8 10 555
3 0
3 6 9

output:

5
3

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 41ms
memory: 3648kb

input:

100000
1 608611451460421713
33155506392034032
1 743116173559300609
6138108577573005
7 364454564010802125
657035115675878115 657035115675878115 657035115675878115 657035115675878115 657035115675878115 292580551665075990 657035115675878115
4 316648374341335221
365788422120542814 182894211060271407 731...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 1st lines differ - expected: '641766957852455745', found: '0'