QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#710625#9426. Relearn through Reviewquannguyen2009WA 1ms5708kbC++231.1kb2024-11-04 20:45:512024-11-04 20:45:52

Judging History

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

  • [2024-11-04 20:45:52]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5708kb
  • [2024-11-04 20:45:51]
  • 提交

answer

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define ii pair<int, int>
#define gcd __gcd
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
using namespace std;

const int N=3e5+5, mod = 1e9+7, inf = 1e18;

int n, k;
int a[N], suf[N];

void solve() {
    cin >> n >> k;
    for (int i=1; i<=n; i++) cin >> a[i];
    suf[n+1] = 0;
    for (int i=n; i>=1; i--) suf[i] = gcd(suf[i+1], a[i]);
    int ans = suf[1];
    int tmp = 0;
    for (int i=1; i<=n; i++) {
        if(gcd(tmp, a[i])!=tmp) {
            int res = 0;
            for (int j=i; j<=n; j++) {
                res = gcd(res, a[j]+k);
                ans = max(ans, gcd(gcd(gcd(tmp, a[i]), res), suf[j+1]));
            }
        }
        tmp = gcd(tmp, a[i]);
    } 
    cout << ans << '\n';
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t; cin >> t;
    while(t--) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5708kb

input:

2
6 2
5 3 13 8 10 555
3 0
3 6 9

output:

1
3

result:

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