QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#688021#9426. Relearn through ReviewAkoasm_XWA 94ms10176kbC++201.5kb2024-10-29 22:43:362024-10-29 22:43:36

Judging History

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

  • [2024-10-29 22:43:36]
  • 评测
  • 测评结果:WA
  • 用时:94ms
  • 内存:10176kb
  • [2024-10-29 22:43:36]
  • 提交

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]);
	if(n==1) ans = max(ans,gl[n] + k);
	else ans = max(ans,gcd(gl[n-1],a[n] + k));
	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: 10064kb

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: 94ms
memory: 10176kb

input:

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

output:

641766957852455745
749254282136873614
657035115675878115
182894211060271407
880411769063535667
560553564512176618
183698346865682381
962990836390050009
616597869896951268
878097339332572161
188820994675344528
361813583202892479
949074379610491450
821422092449828298
632093288650732211
867398114659890...

result:

wrong answer 12th lines differ - expected: '997057718507559252', found: '361813583202892479'