QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#743183#9426. Relearn through ReviewfosovWA 123ms7944kbC++141.5kb2024-11-13 18:31:042024-11-13 18:31:04

Judging History

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

  • [2024-11-13 18:31:04]
  • 评测
  • 测评结果:WA
  • 用时:123ms
  • 内存:7944kb
  • [2024-11-13 18:31:04]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;

#define ll long long 
#define INF 0x3f3f3f3f
#define LNF 0x3f3f3f3f3f3f3f3fll
#define MOD 998244353
#define pii pair<int, int>

#define N 300010
#define K 20

ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}

ll pre[N], suf[N], a[N];

int main() {
#ifdef TEST
    freopen("zz.in", "r+", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t; cin >> t;
    while (t --) {
        ll n, k; cin >> n >> k;
        for (int i = 0; i < n; ++ i) cin >> a[i];

        for (int i = 0; i < n; ++ i) pre[i] = i == 0 ?  a[i] : gcd(pre[i-1], a[i]);
        for (int i = n-1; i >= 0; -- i) suf[i] = i == n-1 ? a[i] : gcd(suf[i+1], a[i]);

        vector<int> pos;
        for (int i = 0; i < n - 1; ++ i) if (pre[i] > pre[i+1]) pos.emplace_back(i);

        ll r0 = a[1], r1 = a[1] + k;
        for (int i = 0; i < n; ++ i) {
            r0 = gcd(r0, a[i]);
            r1 = gcd(r1, a[i] + k);
        }

        ll res = max(r0, r1);

        for (int i = 0; i < pos.size(); ++ i) {
            ll x = -1;
            for (int j = pos[i] + 1; j < n; ++ j) {
                x = x == -1 ? (a[j] + k) : gcd(x, a[j] + k);
                if (j == n - 1) {
                    res = max(res, gcd(pre[pos[i]], x));
                } else {
                    res = max(res, gcd(pre[pos[i]], gcd(x, suf[j+1])));
                }
            }
        }

        cout << res << '\n';
    }
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 7944kb

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: 123ms
memory: 7596kb

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
1
1
962990836390050009
1
878097339332572161
2
997057718507559252
3
37337367838628559
632093288650732211
1
356502546608886970
1
566104642781888753
414849785128019057
2
776741304177800289
383091938972089281
963...

result:

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