QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#640634 | #9426. Relearn through Review | Cu_OH_2 | WA | 102ms | 3792kb | C++20 | 1.2kb | 2024-10-14 14:54:29 | 2024-10-14 14:54:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve()
{
ll n, k;
cin >> n >> k;
vector<ll> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
set<ll> s;
ll g = 0;
for (int i = 0; i < n; ++i)
{
g = __gcd(g, a[i]);
s.insert(g);
}
g = 0;
for (int i = n - 1; i >= 0; --i)
{
g = __gcd(g, a[i]);
s.insert(g);
}
ll ans = 1;
for (auto e : s)
{
vector<int> v;
vector<ll> t(a);
bool f = 1;
for (int i = 0; i < n; ++i)
{
if (a[i] % e && (a[i] + k) % e == 0) v.push_back(i);
}
if (v.size())
{
int lef = *min_element(v.begin(), v.end());
int rig = *max_element(v.begin(), v.end());
for (int i = lef; i <= rig; ++i) t[i] += k;
}
for (int i = 0; i < n; ++i)
{
if (t[i] % e) f = 0;
}
if (f) ans = e;
}
g = 0;
for (int i = 0; i < n; ++i) g = __gcd(g, a[i] + k);
cout << max(g, ans) << '\n';
return;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T = 1;
cin >> T;
while (T--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
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: 102ms
memory: 3792kb
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 2 632093288650732211 1 356502546608886970 789177332497135009 566104642...
result:
wrong answer 7th lines differ - expected: '183698346865682381', found: '1'