QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#790472 | #9426. Relearn through Review | snow_mikumiku | WA | 187ms | 3556kb | C++20 | 1.4kb | 2024-11-28 12:27:08 | 2024-11-28 12:27:09 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
void solve()
{
LL n, k, mx = 0, mn = 2e18;
cin >> n >> k;
vector <LL> A(n + 1);
for(int i = 1; i <= n; i++) cin >> A[i];
LL ans = A[1] + k;
for(int i = 1; i <= n; i++) {
ans = gcd(ans, A[i] + k);
}
LL GCD = A[1];
for(int i = 1; i <= n; i++) {
LL up = GCD;
GCD = gcd(GCD, A[i]);
if(up > GCD) {
LL f = 1, res = A[i - 1];
for(int j = i; j <= n; j++) {
if(gcd(A[j] + k, res) < gcd(A[j], res)) f = 0;
if(f) res = gcd(res, A[j] + k);
else res = gcd(res, A[j]);
}
ans = max(ans, res);
}
}
reverse(A.begin() + 1, A.end());
GCD = A[1];
for(int i = 1; i <= n; i++) {
LL up = GCD;
GCD = gcd(GCD, A[i]);
if(up > GCD) {
LL f = 1, res = A[i - 1];
for(int j = i; j <= n; j++) {
if(gcd(A[j] + k, res) < gcd(A[j], res)) f = 0;
if(f) res = gcd(res, A[j] + k);
else res = gcd(res, A[j]);
}
ans = max(ans, res);
}
}
ans = max(ans, GCD);
cout << ans << '\n';
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
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: 3480kb
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: 187ms
memory: 3556kb
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 731576844241085628 880411769063535667 560553564512176618 183698346865682381 962990836390050009 616597869896951268 878097339332572161 188820994675344528 997057718507559252 949074379610491450 37337367838628559 632093288650732211 3771217139073309...
result:
wrong answer 4th lines differ - expected: '182894211060271407', found: '731576844241085628'