QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#743196 | #9426. Relearn through Review | fosov | WA | 111ms | 7872kb | C++14 | 1.5kb | 2024-11-13 18:33:28 | 2024-11-13 18:33:28 |
Judging History
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[0], r1 = a[0] + 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: 0ms
memory: 7700kb
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: 111ms
memory: 7872kb
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 182894211060271407 880411769063535667 560553564512176618 1 962990836390050009 616597869896951268 878097339332572161 188820994675344528 997057718507559252 949074379610491450 37337367838628559 632093288650732211 1 356502546608886970 789177332497...
result:
wrong answer 7th lines differ - expected: '183698346865682381', found: '1'