QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#604619 | #9426. Relearn through Review | Lanmosheng | WA | 41ms | 5696kb | C++14 | 956b | 2024-10-02 12:33:46 | 2024-10-02 12:33:47 |
Judging History
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'