QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#609027#9426. Relearn through ReviewNull_ResotWA 130ms3828kbC++201.6kb2024-10-04 10:18:112024-10-04 10:18:13

Judging History

This is the latest submission verdict.

  • [2024-10-04 10:18:13]
  • Judged
  • Verdict: WA
  • Time: 130ms
  • Memory: 3828kb
  • [2024-10-04 10:18:11]
  • Submitted

answer

#include <bits/stdc++.h>

using i64 = long long;
using u64 = unsigned long long;

typedef std::pair<long long, long long> PII;
const int mod = 998244353;
const int N = 2e6 + 1000;
const int INF = 0x3f3f3f3f;
const long long LINF = 1e18;
const double eps = 1e-12;
const double pi = std::acos(-1);
std::mt19937_64 rnd(std::random_device{}());

void solve() {
    i64 n, k;
    std::cin >> n >> k;
    std::vector<i64> a(n + 1), pre(n + 1), suf(n + 2);
    i64 ans = 0, res = 0;

    for (int i = 1; i <= n; i ++) std::cin >> a[i], ans = std::__gcd(ans, a[i]), res = std::__gcd(res, a[i] + k);
    for (int i = 1; i <= n; i ++) pre[i] = std::__gcd(pre[i - 1], a[i]);
    for (int i = n; i >= 1; i --) suf[i] = std::__gcd(suf[i + 1], a[i]);

    ans = std::max(ans, res);

    std::vector<PII> b;
    for (int i = 1; i <= n; i ++) {
        if (b.empty()) b.emplace_back(pre[i], i);
        if (b.back().first == pre[i]) {
            b.pop_back();
            b.emplace_back(pre[i], i);
        } else
            b.emplace_back(pre[i], i);
    }

    for (auto [preg, st] : b) {
        i64 g = 0;
        for (int r = st + 1; r <= n; r ++) {
            ans = std::max(ans, std::__gcd(std::gcd(preg, g), std::__gcd(a[r] + k, suf[r + 1])));
            g = std::__gcd(g, a[r] - a[r + 1]);
        }
    }

    std::cout << ans << "\n";
}

signed main() {
    std::ios::sync_with_stdio(false), std::cin.tie(nullptr), std::cout.tie(nullptr);
    
    int tmp = 1;
    
    std::cin >> tmp;

    while (tmp--)
        solve();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

result:

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