QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#775111#9426. Relearn through ReviewLcaokaiWA 142ms3540kbC++201.1kb2024-11-23 14:46:082024-11-23 14:46:08

Judging History

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

  • [2024-11-23 14:46:08]
  • 评测
  • 测评结果:WA
  • 用时:142ms
  • 内存:3540kb
  • [2024-11-23 14:46:08]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'

void oper(int testcase_i) {
    ll n, k;
    cin >> n >> k;

    vector<ll> a(n + 1), a_k(n + 1);
    vector<ll> prpr(n + 2);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a_k[i] = a[i] + k;
        prpr[i] = __gcd(prpr[i - 1], a[i]);
    }

    vector<ll> ne(n + 10);
    ne[n] = a[n];
    for (int i = n - 1; i >= 1; i--) {
        ne[i] = __gcd(ne[i + 1], a[i]);
    }

    ll ans = 1;
    ll prgcdx = 0;
    for (int l = 0; l <= n; l++) {
        ll gcdx = __gcd(prgcdx, a[l]);
        if (gcdx == prpr[l + 1]) {
            continue;
        }
        prgcdx = gcdx;
        
        ll gcdrnow = 0;
        for (int r = l + 1; r <= n; r++) {
            gcdrnow = __gcd(gcdrnow, a_k[r]);
            ans = max(ans, __gcd(gcdx, __gcd(gcdrnow, ne[r + 1])));
        }
    }
    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int ttt = 1;
    cin >> ttt;
    for (int i = 1; i <= ttt; i++) {
        oper(i);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 142ms
memory: 3540kb

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
365788422120542814
880411769063535667
560553564512176618
183698346865682381
962990836390050009
616597869896951268
878097339332572161
188820994675344528
997057718507559252
949074379610491450
37337367838628559
632093288650732211
3771217139073309...

result:

wrong answer 4th lines differ - expected: '182894211060271407', found: '365788422120542814'