QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#614456#9426. Relearn through ReviewXiaoTieWA 162ms3832kbC++201.2kb2024-10-05 16:23:002024-10-05 16:23:01

Judging History

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

  • [2024-10-05 16:23:01]
  • 评测
  • 测评结果:WA
  • 用时:162ms
  • 内存:3832kb
  • [2024-10-05 16:23:00]
  • 提交

answer

#include <bits/stdc++.h>
#pragma GCC optimize(3)
#define int long long
#define llu unsigned long long
#define endl "\n"
#define inf 0x3f3f3f3f
#define debug cout << "****************" << endl
using namespace std;

typedef pair<int, int> PII;

const int N = 1e6 + 7;

void solve()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n + 7);
    vector<int> pre(n + 7);
    vector<int> suf(n + 7);
    int ans = 0;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++) {
        pre[i] = gcd(pre[i - 1], a[i]);
    }
    for (int i = n; i >= 1; i--) {
        suf[i] = gcd(suf[i + 1], a[i]);
    }
    pre[0] = 1e18;
    for (int i = 1; i <= n; i++) {
        if (pre[i] < pre[i - 1]) {
            int gc = 0;
            for (int j = i; j <= n; j++) {
                gc = gcd(gc, a[j] + k);
                ans = max(ans, gcd(gcd(pre[i - 1], gc), suf[j + 1]));
            }
        }
    }
    ans = max(ans, pre[n]);
    cout << ans << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    cin >> T;
    while (T--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 162ms
memory: 3832kb

input:

100000
1 608611451460421713
33155506392034032
1 743116173559300609
6138108577573005
7 364454564010802125
657035115675878115 657035115675878115 657035115675878115 657035115675878115 657035115675878115 292580551665075990 657035115675878115
4 316648374341335221
365788422120542814 182894211060271407 731...

output:

33155506392034032
6138108577573005
657035115675878115
182894211060271407
880411769063535667
98423435849394582
1
962990836390050009
484915690810412536
878097339332572161
149180825015886938
361813583202892479
915781395066183375
37337367838628559
632093288650732211
16
10
494408344393555851
566104642781...

result:

wrong answer 1st lines differ - expected: '641766957852455745', found: '33155506392034032'