QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#604622#9426. Relearn through ReviewLanmoshengWA 132ms5764kbC++14982b2024-10-02 12:34:212024-10-02 12:34:22

Judging History

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

  • [2024-10-02 12:34:22]
  • 评测
  • 测评结果:WA
  • 用时:132ms
  • 内存:5764kb
  • [2024-10-02 12:34:21]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
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;
}
signed 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: 5764kb

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: 132ms
memory: 5716kb

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
15
3
880411769063535667
0
1
962990836390050009
0
878097339332572161
0
3
0
37337367838628559
1
1
2
0
1
414849785128019057
0
1
1
963758727749334806
1
0
151003075535938163
0
538014370559186083
1
3
938462768553385210
4
557547233762973087
3
0
2
777819466140221104
2
31
0
926534262599314442
2
0
8027742...

result:

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