QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#661546#9426. Relearn through Reviewwangxiaorui#WA 277ms7752kbC++141.1kb2024-10-20 16:45:542024-10-20 16:45:54

Judging History

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

  • [2024-10-20 16:45:54]
  • 评测
  • 测评结果:WA
  • 用时:277ms
  • 内存:7752kb
  • [2024-10-20 16:45:54]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define F(x,y,z) for(int x=(y);x<=(z);x++)
using namespace std;
const int N=300010;
int n;
ll k;
ll a[N];
ll pre[N],suf[N];
ll ans;
ll gcd(ll a,ll b){
    if(!b) return a;
    return gcd(b,a%b);
}
void solve(){
    cin>>n>>k;
    ans=0;
    ll g;
    for(int i=1;i<=n;i++) cin>>a[i];
    pre[1]=a[1];g=a[1]+k;
    for(int i=2;i<=n;i++){
        pre[i]=gcd(pre[i-1],a[i]);
        g=gcd(g,a[i]+k);
        // cout<<i<<' '<<pre[i]<<endl;
    }
    suf[n]=a[n];
    for(int i=n-1;i>=1;i--) suf[i]=gcd(suf[i+1],a[i]);
    ans=max(ans,pre[n]);ans=max(ans,g);
    for(int i=2;i<=n;i++)
        if(pre[i]!=pre[i-1]){
            // cout<<i<<endl;
            ll sum=pre[i-1];
            // cout<<sum<<endl;
            for(int j=i;j<=n;j++){
                sum=gcd(sum,a[j]+k);
                // cout<<sum<<' ';
                if(j<n) ans=max(ans,gcd(sum,suf[j+1]));
            }
            // cout<<endl;
            ans=max(ans,sum);
        }
    cout<<ans<<endl;
}
int main(){
    int T;
    cin>>T;
    while(T--) 
        solve();
    return 0;
}

详细

Test #1:

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

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: 277ms
memory: 7752kb

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
1
962990836390050009
616597869896951268
878097339332572161
188820994675344528
997057718507559252
949074379610491450
37337367838628559
632093288650732211
1
356502546608886970
789177332497...

result:

wrong answer 7th lines differ - expected: '183698346865682381', found: '1'