QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#688016 | #9426. Relearn through Review | Akoasm_X | WA | 86ms | 10080kb | C++20 | 1.4kb | 2024-10-29 22:40:06 | 2024-10-29 22:40:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define int long long
typedef long long LL;
inline int read(){
int x = 0 , f = 1 ; char c = getchar() ;
while( c < '0' || c > '9' ) { if( c == '-' ) f = -1 ; c = getchar() ; }
while( c >= '0' && c <= '9' ) { x = x * 10 + c - '0' ; c = getchar() ; }
return x * f ;
}
const int maxn = 3e5+20;
int n,k,ans;
int a[maxn],b[maxn][20],gl[maxn],gr[maxn];
int gcd(int x,int y){
return y ? gcd(y,x % y) : x;
}
int g(int l,int r){
int d = (r - l + 1);
int t = log2(d);
return gcd(b[l][t],b[r - (1<<t) + 1][t]);
}
void solve(){
n = read();k = read();ans = 0;
for(int i=1;i<=n;i++) a[i] = read();
gl[1] = a[1];gr[n] = a[n];
for(int i=n-1;i>=1;i--) gr[i] = gcd(gr[i+1],a[i]);
for(int i=2;i<=n;i++) b[i][0] = abs(a[i] - a[i-1]);
for(int i=1;i<20;i++){
for(int j=2;j+(1<<i)-1<=n;j++){
b[j][i] = gcd(b[j][i-1],b[j+(1<<(i-1))][i-1]);
}
}
for(int i=2;i<=n;i++){
gl[i] = gcd(gl[i-1],a[i]);
if(gl[i] < gl[i-1]){
for(int j=i-1;j<=n;j++){
int tmp = a[j]+k;
if(i-1!=1) tmp = gcd(tmp,gl[i-2]);
if(j!=n) tmp = gcd(tmp,gr[j+1]);
if(i!=j) tmp = gcd(tmp,g(i+1,j));
ans = max(ans,tmp);
}
}
}
ans = max(ans,gl[n]);
printf("%lld\n",ans);
}
signed main(){
// freopen("1.txt","r",stdin);
int T = 1;
T = read();
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 10028kb
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: 86ms
memory: 10080kb
input:
100000 1 608611451460421713 33155506392034032 1 743116173559300609 6138108577573005 7 364454564010802125 657035115675878115 657035115675878115 657035115675878115 657035115675878115 657035115675878115 292580551665075990 657035115675878115 4 316648374341335221 365788422120542814 182894211060271407 731...
output:
33155506392034032 6138108577573005 657035115675878115 182894211060271407 880411769063535667 98423435849394582 183698346865682381 962990836390050009 484915690810412536 878097339332572161 149180825015886938 361813583202892479 915781395066183375 821422092449828298 632093288650732211 867398114659890467 ...
result:
wrong answer 1st lines differ - expected: '641766957852455745', found: '33155506392034032'