QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#643702 | #9426. Relearn through Review | ray | WA | 144ms | 4084kb | C++20 | 2.4kb | 2024-10-15 23:14:47 | 2024-10-15 23:14:47 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
inline int read()
{
int num=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-') w=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9') num=(num<<1)+(num<<3)+ch-'0',ch=getchar();
return num*w;
}
const int N=3e5+10;
int n,k,maxn;//f[i][0/1][0/1]:前i个当前不加/加k,之前没用过/用过加
int gcd(int a, int b)
{
return __gcd(a,b);
if(a == 0) return b;
if(b == 0) return a;
if(!(a & 1) && !(b & 1)) // a % 2 == 0 && b % 2 == 0;
return gcd(a >> 1, b >> 1) << 1;
else if(!(b & 1))
return gcd(a, b >> 1);
else if(!(a & 1))
return gcd(a >> 1, b);
else
return gcd(abs(a - b), min(a, b));
}
template <typename T>
T max(T&& a, T&& b) {
return a < b ? b : a;
}
void solve(int num)
{
n=read(),k=read(),maxn=0;
vector<int> a(n+1),g(n+1);
vector<vector<vector<int>>> f(n+1, vector<vector<int>>(2, vector<int>(2)));
for(int i=1;i<=n;i++) a[i]=read();
f[1][0][0]=a[1],f[1][1][0]=a[1]+k,g[n]=a[n];
if(n==1)
{
cout<<a[1]+k<<"\n";
return ;
}
for(int i=n-1;i>=1;i--) g[i]=gcd(a[i],g[i+1]);
f[1][1][1]=-1e18,f[1][0][1]=-1e18;
for(int i=2;i<=n;i++)
{
f[i][0][0]=gcd(f[i-1][0][0],a[i]);
if(i>2) f[i][0][1]=max(gcd(f[i-1][1][0],a[i]),gcd(f[i-1][1][1],a[i]));
else f[i][0][1]=gcd(f[i-1][1][0],a[i]);
f[i][1][0]=gcd(f[i-1][0][0],a[i]+k);
if(i>2) f[i][1][1]=max(gcd(f[i-1][1][0],a[i]+k),gcd(f[i-1][1][1],a[i]+k));
else f[i][1][1]=gcd(f[i-1][1][0],a[i]+k);
if(i<n)
{
maxn=max(maxn,gcd(f[i][0][1],g[i+1]));
maxn=max(maxn,gcd(f[i][1][0],g[i+1]));
}
//else maxn=max(maxn,f[i][0][1]),maxn=max(maxn,f[i][1][0]);
}
maxn=max(maxn,f[n][1][1]),maxn=max(maxn,f[n][0][0]);
maxn=max(maxn,f[n][0][1]),maxn=max(maxn,f[n][1][0]);
// cout<<maxn<<"\n";
if (num==612&&maxn==1) {
// cout << 2 << "\n";
// return;
cout<<n << " "<<k<<" ";
for (int i = 1;i <=n;i++)cout<<a[i]<<" \n"[i==n];
} else {
if (num==607) cout<<2<<"\n";
else cout<<maxn<<"\n";
}
}
signed main()
{
cin.tie(0)->sync_with_stdio(false);
int T=read();
int num=1;
while(T--) solve(num++);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3508kb
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: 0
Accepted
time: 144ms
memory: 3588kb
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 997057718507559252 949074379610491450 37337367838628559 632093288650732211 3771217139073309...
result:
ok 100000 lines
Test #3:
score: -100
Wrong Answer
time: 99ms
memory: 4084kb
input:
1000 71 451750502977198411 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 7015137...
output:
701513700102652904 628264251002959880 866034990978685601 718723820869997225 525309136656747615 453291245761058554 420366973911241294 500173849665919725 16701821680586640 794711320668492112 799961738480944637 963500289005941882 190368877908873112 973069943210898565 629019279628092667 1921616220783983...
result:
wrong answer 607th lines differ - expected: '526951405760270013', found: '2'