QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#609011#9426. Relearn through ReviewNull_ResotWA 115ms3676kbC++201.4kb2024-10-04 10:14:342024-10-04 10:14:35

Judging History

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

  • [2024-10-04 10:14:35]
  • 评测
  • 测评结果:WA
  • 用时:115ms
  • 内存:3676kb
  • [2024-10-04 10:14:34]
  • 提交

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;

    for (int i = 1; i <= n; i ++) std::cin >> a[i], ans = std::__gcd(ans, a[i]);
    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]);

    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]) std::prev(b.end())->second = 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] + k);
        }
    }

    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: 3676kb

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: 115ms
memory: 3604kb

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
1
2
494408344393555851
56610464278188...

result:

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