QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#643686#9426. Relearn through ReviewrayWA 149ms52300kbC++202.3kb2024-10-15 23:07:472024-10-15 23:07:52

Judging History

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

  • [2024-10-15 23:07:52]
  • 评测
  • 测评结果:WA
  • 用时:149ms
  • 内存:52300kb
  • [2024-10-15 23:07:47]
  • 提交

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==607&&maxn==1) {
        cout<<n << " "<<k<<" ";
        for (int i = 1;i <=n;i++)cout<<a[i]<<" \n"[i==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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3632kb

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: 149ms
memory: 3608kb

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: 0
Accepted
time: 100ms
memory: 4200kb

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:

ok 1000 lines

Test #4:

score: 0
Accepted
time: 89ms
memory: 5608kb

input:

100
5516 16561406822518327
121909691713696369 226403713182578971 940446193219943418 505054437099599243 505054437099599243 383144745385902874 470223096609971709 714042480037364447 417976085875530408 783705161016619515 888199182485502117 208988042937765204 330897734651461573 818536501506247049 7488738...

output:

17415670244813767
678667366385241526
375190657607916623
343566816881610443
293858497297593293
545063989451911922
101584687520632945
923261939978554511
245471164671296626
996567332718295422
871411820593738277
999473841903341933
575286590792404442
298698210937205101
265822932252018295
4113318308187297...

result:

ok 100 lines

Test #5:

score: 0
Accepted
time: 112ms
memory: 19620kb

input:

10
2651 1901143105096273
954803577560210292 636535718373473528 159133929593368382 159133929593368382 954803577560210292 477401788780105146 636535718373473528 636535718373473528 954803577560210292 636535718373473528 318267859186736764 636535718373473528 636535718373473528 318267859186736764 795669647...

output:

159133929593368382
793024501989621764
454059328664071477
113729984568648330
507863600649451091
779491329333959710
821665805532903623
384579792180981183
356029896436006899
340683633028457433

result:

ok 10 lines

Test #6:

score: 0
Accepted
time: 83ms
memory: 31176kb

input:

3
31056 13873801082583029
316385357210519324 316385357210519324 316385357210519324 949156071631557972 632770714421038648 949156071631557972 316385357210519324 316385357210519324 316385357210519324 316385357210519324 632770714421038648 949156071631557972 316385357210519324 316385357210519324 31638535...

output:

316385357210519324
399693130963531970
229449205713014908

result:

ok 3 lines

Test #7:

score: 0
Accepted
time: 90ms
memory: 52208kb

input:

1
300000 309955051600565498
497784205512766609 995568411025533218 995568411025533218 995568411025533218 995568411025533218 497784205512766609 497784205512766609 995568411025533218 995568411025533218 995568411025533218 497784205512766609 995568411025533218 497784205512766609 497784205512766609 497784...

output:

497784205512766609

result:

ok single line: '497784205512766609'

Test #8:

score: 0
Accepted
time: 46ms
memory: 52204kb

input:

1
300000 1
7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7...

output:

7

result:

ok single line: '7'

Test #9:

score: 0
Accepted
time: 37ms
memory: 52300kb

input:

1
300000 60
66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 ...

output:

66

result:

ok single line: '66'

Test #10:

score: 0
Accepted
time: 72ms
memory: 52280kb

input:

1
300000 522555291
775151491735355392 775151491735355392 775151491735355392 775151491735355392 775151491735355392 775151491735355392 775151491735355392 775151491735355392 775151491735355392 775151491735355392 775151491735355392 775151491735355392 775151491735355392 775151491735355392 775151491735355...

output:

721916083

result:

ok single line: '721916083'

Test #11:

score: 0
Accepted
time: 35ms
memory: 52276kb

input:

1
300000 0
6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6...

output:

1

result:

ok single line: '1'

Test #12:

score: 0
Accepted
time: 32ms
memory: 52256kb

input:

1
300000 3
64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 6...

output:

4

result:

ok single line: '4'

Test #13:

score: 0
Accepted
time: 54ms
memory: 52296kb

input:

1
300000 634838941
826705280146341888 826705280146341888 826705280146341888 826705280146341888 826705280146341888 826705280146341888 826705280146341888 826705280146341888 826705280146341888 826705280146341888 826705280146341888 826705280146341888 826705280146341888 826705280146341888 826705280146341...

output:

720994598

result:

ok single line: '720994598'

Test #14:

score: 0
Accepted
time: 62ms
memory: 52280kb

input:

1
300000 236226483
980299602173362176 980299602173362176 980299602173362176 980299602173362176 980299602173362176 980299602173362176 980299602173362176 980299602173362176 980299602173362176 980299602173362176 980299602173362176 980299602173362176 980299602173362176 980299602173362176 980299602173362...

output:

721363081

result:

ok single line: '721363081'

Test #15:

score: -100
Wrong Answer
time: 42ms
memory: 3592kb

input:

75000
4 0
1 1 1 1
4 1
1 1 1 1
4 2
1 1 1 1
4 3
1 1 1 1
4 4
1 1 1 1
4 0
2 1 1 1
4 1
2 1 1 1
4 2
2 1 1 1
4 3
2 1 1 1
4 4
2 1 1 1
4 0
3 1 1 1
4 1
3 1 1 1
4 2
3 1 1 1
4 3
3 1 1 1
4 4
3 1 1 1
4 0
4 1 1 1
4 1
4 1 1 1
4 2
4 1 1 1
4 3
4 1 1 1
4 4
4 1 1 1
4 0
5 1 1 1
4 1
5 1 1 1
4 2
5 1 1 1
4 3
5 1 1 1
4 4
5 ...

output:

1
2
3
4
5
1
2
1
2
1
1
2
3
2
1
1
2
3
4
1
1
2
1
4
5
1
1
1
1
1
1
2
1
2
1
1
1
1
1
1
1
2
1
2
1
1
1
1
1
1
1
2
1
2
1
1
2
1
2
1
1
2
3
2
1
1
2
1
2
1
1
2
1
2
1
1
1
3
1
1
1
2
1
2
1
1
1
3
1
1
1
2
3
4
1
1
1
1
1
1
1
2
1
4
1
1
2
1
2
1
1
2
1
2
1
1
2
1
4
1
1
2
1
4
5
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

wrong answer 607th lines differ - expected: '2', found: '4 1 2 5 5 1'