QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#658775 | #9426. Relearn through Review | XiaoYang3 | WA | 141ms | 3644kb | C++23 | 1.7kb | 2024-10-19 17:35:32 | 2024-10-19 17:35:34 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
ll n, m, k;
const int N = 4e5 + 5;
const int P = 1e9 + 7;
void solve() {
cin >> n >> k;
vector<ll> a(n + 2);
vector<ll> pre(n + 2), suf(n + 2);
map<ll, vector<int>> mp1;
map<ll, vector<int>> mp2;
ll ans = 1;
for (int i = 1; i <= n; i++) {
cin >> a[i];
pre[i] = __gcd(a[i], pre[i - 1]);
mp1[pre[i]].push_back(i);
}
mp1[a[1] + k].push_back(1);
mp2[a[n] + k].push_back(n);
for (int i = n; i >= 1; i--) {
suf[i] = __gcd(a[i], suf[i + 1]);
mp2[suf[i]].push_back(i);
}
for (auto [x, y] : mp2) {
if (mp1[x].size() == 0) {
mp1[x].push_back(0);
}
}
for (auto [x, y] : mp1) {
if (mp2[x].size() == 0) {
mp2[x].push_back(n + 1);
}
}
for (auto [x, y] : mp1) {
auto l = y[y.size() - 1];
if (mp2[x].size()) {
auto r = mp2[x][mp2[x].size() - 1];
// cout << x << ' ' << l << ' ' << r << ' ';
if (l >= r) {
ans = max(ans, x);
} else {
for (int i = l + 1; i <= r - 1; i++) {
if ((a[i] + k) % x != 0) {
break;
}
if (i == r - 1) {
ans = max(ans, x);
}
}
}
}
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int _ = 1;
cin >> _;
while (_--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3512kb
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: 141ms
memory: 3644kb
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 1 560553564512176618 1 962990836390050009 616597869896951268 3 188820994675344528 361813583202892479 949074379610491450 1 632093288650732211 1 2 789177332497135009 1 1 134561004312215460 1 383091938972089281 1 80953529911389...
result:
wrong answer 5th lines differ - expected: '880411769063535667', found: '1'