QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#844897#9426. Relearn through ReviewciuimWA 99ms8076kbC++142.0kb2025-01-06 12:11:522025-01-06 12:11:52

Judging History

This is the latest submission verdict.

  • [2025-01-06 12:11:52]
  • Judged
  • Verdict: WA
  • Time: 99ms
  • Memory: 8076kb
  • [2025-01-06 12:11:52]
  • Submitted

answer

bool M1;
#define look_memory cerr<<abs(&M2-&M1)/1024.0/1024<<" MB\n"
#define look_time cerr<<(clock()-Time)*1.0/CLOCKS_PER_SEC<<'\n'
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <cstring>
#include <array>
#include <algorithm>
#include <queue>
#include <vector>
#include <bitset>
#include <ctime>
#include <cstdlib>
#include <random>
#include <set>
#include <ctime>
#include <map>
#include <stack>
#include <unordered_map>
#include <assert.h>
#include <unordered_set>
#define i128 __int128
#define ll long long
#define uint unsigned
#define ull unsigned long long
#define ld long double
#define fo(a,b,c) for(ll a=b;a<=c;++a)
#define re(a,b,c) for(ll a=b;a>=c;--a)
#define pii pair<ll,ll>
#define pdd pair<db,db>
#define fi first
#define pb push_back
#define se second
#define ite set<array<ll,3>> ::iterator
#define vite vector<ll> ::iterator
#define mite map<ll,ll> ::iterator
using namespace std;
const ll mod=998244353;
inline ll gi()
{
	ll x = 0, f = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9')
	{
		if (ch == '-')
			f = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9')
	{
		x = (x<<1) + (x<<3) + (ch^48);
		ch = getchar();
	}
	return x * f;
}
ll _=1;
const ll inf=2e17+5,iinf=1e9+5;
const ll N=300005;
ll gcd(ll a,ll b)
{
	if(b==0) return a;
	return gcd(b,a%b);
}
ll a[N],suf[N],pre[N];
void sol()
{
	ll n=gi(),k=gi();
	fo(i,1,n) a[i]=gi();
	suf[n+1]=0;
	re(i,n,1)
	{
		suf[i]=gcd(suf[i+1],a[i]);
	}
	fo(i,1,n)
	{
		pre[i]=gcd(pre[i-1],a[i]);
	}
	ll ans=pre[n],d=0;
	fo(i,1,n)
	{
		d=gcd(d,a[i]+k);
		ans=max(ans,gcd(d,suf[i+1]));
	}
	fo(i,1,n)
	{
		if(pre[i]!=pre[i-1])
		{
			d=0;
			fo(j,i+1,n)
			{
				d=gcd(d,a[j]+k);
				ans=max(ans,gcd(d,gcd(pre[i],suf[j+1])));
			}
		}
	}
	cout<<ans;
}
bool M2;
int main()
{
	int Time=clock();
	look_memory;
	_=gi();
	while(_--)
	{
		sol();
		printf("\n");
	}
	look_time;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7984kb

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: 99ms
memory: 8076kb

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
15
3
880411769063535667
560553564512176618
183698346865682381
962990836390050009
616597869896951268
878097339332572161
188820994675344528
997057718507559252
949074379610491450
37337367838628559
1
377121713907330928
356502546608886970
789177332497135009
2
4148497...

result:

wrong answer 3rd lines differ - expected: '657035115675878115', found: '15'