QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#623602#9426. Relearn through ReviewZxyoulWA 116ms5844kbC++201.3kb2024-10-09 13:23:182024-10-09 13:23:32

Judging History

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

  • [2024-10-09 13:23:32]
  • 评测
  • 测评结果:WA
  • 用时:116ms
  • 内存:5844kb
  • [2024-10-09 13:23:18]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 3e5 + 10;
int a[N];
int gpre[N], gsuf[N];
void solve() {
    int n, k; cin >> n >> k;
    int o = 0;
    vector< int > id;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        if(o != __gcd(o, a[i])) {
            id.push_back(i);
        }
        o = __gcd(o, a[i]);
    }
    a[n + 1] = 0;
    for(int i = 1; i <= n; i++) {
        gpre[i] = __gcd(gpre[i - 1], a[i]);
    }

    for(int i = n; i >= 1; i--) {
        gsuf[i] = __gcd(gsuf[i + 1], a[i]);
    }

    if(id.back() != n) {
        id.push_back(n);
    }
    int ans = 0;
    for(int i = 0; i < id.size(); i++) {
        int l = id[i]; int cur = gpre[l - 1];
        for(int r = l; r <= n; r++) {
            cur = __gcd(cur, a[r] + k);
            ans = max(ans, __gcd(cur, gsuf[r + 1]));
        }
    }
    for(int i = 0; i < id.size(); i++) {
        int r = id[i] - 1; int cur = gsuf[r + 1];
        for(int l = r; l >= 1; l--) {
            cur = __gcd(cur, a[l] + k);
            ans = max(ans, __gcd(cur, gpre[l - 1]));
        }
    }

    cout << max(o, ans) << '\n';
}
signed main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int t= 1;
    cin >> t;
    while(t--)solve();
}

详细

Test #1:

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

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: 116ms
memory: 5844kb

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
3
1
98423435849394582
1
3
484915690810412536
3
149180825015886938
361813583202892479
915781395066183375
3
632093288650732211
1
2
494408344393555851
1
1
118387461231999184
1
383091938972089281
1
2
580787185875674097
3
443516810815251949
1
1
255...

result:

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