QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#641362 | #9426. Relearn through Review | ucup-team004 | WA | 137ms | 3664kb | C++23 | 1.2kb | 2024-10-14 20:10:15 | 2024-10-14 20:10:16 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
void solve() {
int n;
i64 k;
std::cin >> n >> k;
std::vector<i64> a(n);
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
auto get = [&](int i, i64 g) {
std::vector<i64> pre(n + 1), suf(n + 1);
for (int j = i; j < n; j++) {
pre[j + 1] = std::gcd(pre[j], a[j] + k);
}
for (int j = n - 1; j >= i; j--) {
suf[j] = std::gcd(suf[j + 1], a[j]);
}
i64 ans = 0;
for (int j = i; j <= n; j++) {
ans = std::max(ans, std::gcd(g, std::gcd(pre[j], suf[j])));
}
return ans;
};
i64 g = 0;
i64 ans = 0;
for (int i = 0; i < n; i++) {
i64 ng = std::gcd(ng, a[i]);
if (ng != g) {
ans = std::max(ans, get(i, g));
}
g = ng;
}
ans = std::max(ans, g);
std::cout << ans << "\n";
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
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: 137ms
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 15 3 1 560553564512176618 183698346865682381 3 616597869896951268 6 188820994675344528 997057718507559252 949074379610491450 3 1 377121713907330928 356502546608886970 789177332497135009 2 2 134561004312215460 3 3 2 12 649630151112107049 3 815531812998319264 1 2 ...
result:
wrong answer 3rd lines differ - expected: '657035115675878115', found: '15'