QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#751787 | #9426. Relearn through Review | Jorisy | WA | 175ms | 5944kb | C++14 | 770b | 2024-11-15 20:41:54 | 2024-11-15 20:41:55 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n;
ll k,a[300005],pre[300005],suf[300005];
void sol()
{
scanf("%d%lld",&n,&k);
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
pre[i]=__gcd(pre[i-1],a[i]);
}
suf[n+1]=0;
for(int i=n;i;i--) suf[i]=__gcd(suf[i+1],a[i]);
ll ans=pre[n];
for(int i=1;i<=n;i++)
{
if(pre[i]==pre[i-1]) continue;
ll g=pre[i-1];
for(int j=i;j<=n;j++)
{
g=__gcd(g,a[j])+k;
ans=max(ans,__gcd(g,suf[j+1]));
}
}
printf("%lld\n",ans);
}
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
int t;
scanf("%d",&t);
while(t--) sol();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5944kb
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: 175ms
memory: 5900kb
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 364454564010802620 316648374341335224 435076050473321787 560553564512176618 328926846394166853 471702364484802729 616597869896951268 714026343827254095 188820994675344528 635244135304666776 949074379610491450 4117523687675031 105293193934201214 49027640075255953...
result:
wrong answer 3rd lines differ - expected: '657035115675878115', found: '364454564010802620'