QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#717922#9426. Relearn through ReviewcrazymoonWA 132ms3664kbC++201.2kb2024-11-06 19:17:062024-11-06 19:17:12

Judging History

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

  • [2024-11-06 19:17:12]
  • 评测
  • 测评结果:WA
  • 用时:132ms
  • 内存:3664kb
  • [2024-11-06 19:17:06]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
const double eps = 1e-8;

void solve() {
    int n, k, res = 0;
    cin >> n >> k;
    vector<int> a(n + 1), nxt(n + 1);
    for (int i = 1; i <= n; ++i)  cin >> a[i];
    nxt[n] = a[n];
    for (int i = n - 1; i >= 1; --i)  nxt[i] = __gcd(nxt[i + 1], a[i]);
    for (int i = 1, cur = 0; i <= n; ++i) {
        if(cur == 0 || a[i] % cur != 0) {
            if(cur == 0)  res = max(res, __gcd(a[i] + k, nxt[i + 1]));
            else  res = max(res, __gcd(cur, __gcd(a[i] + k, nxt[i + 1])));
            int d = cur;
            if(cur == 0)  d = abs(a[i + 1] - a[i]);
            else  d = __gcd(d, abs(a[i + 1] - a[i]));
            for (int r = i + 1; r <= n; ++r) {
                res = max(res, __gcd(d, __gcd(a[r] + k, nxt[r + 1])));
                if(r + 1 <= n)  d = __gcd(d, abs(a[r + 1] - a[r]));
            }
        }
        if(cur == 0)  cur = a[i];
        else  cur = __gcd(cur, a[i]);
    }
    cout << res << '\n';
}

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

详细

Test #1:

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

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: 132ms
memory: 3664kb

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
9
1
1
183698346865682381
3
1
6
24
3
1
37337367838628559
632093288650732211
377121713907330928
2
1
2
2
2
9
383091938972089281
1
809535299113892268
1
1
1
1
1
3
1
4
557547233762973087
3
3
515597846986915098
777819466140221104
5
657659966947439521...

result:

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