QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#855786 | #9738. Make It Divisible | xueman | WA | 0ms | 3624kb | C++23 | 1.4kb | 2025-01-13 10:50:29 | 2025-01-13 10:50:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
const int N = 1000 + 10;
const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
int a[maxn];
ll n, m;
ll cnt, ans;
void check(int x)
{
for (int i = 2; i <= n; i++)
{
int t1 = a[i] + x, t2 = a[i - 1] + x;
if (t1 < t2)
swap(t1, t2);
if (t1 % t2 != 0)
return;
}
ans += x;
cnt++;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--)
{
cin >> n >> m;
int mx = inf;
set<int> s;
for (int i = 1; i <= n; i++)
cin >> a[i], mx = min(mx, a[i]), s.insert(a[i]);
if (s.size() == 1)
{
cout << m << ' ' << m * (m + 1) / 2 << endl;
continue;
}
int g = 0;
for (int i = 2; i <= n; i++)
g = __gcd(abs(a[i] - a[i - 1]), g);
cnt = ans = 0;
for (int i = 1; i * i <= g; i++)
{
if (g % i == 0)
{
if (i - mx <= m && i - mx >= 1)
check(i - mx);
if (i != g / i && g / i - mx <= m && g / i - mx >= 1)
check(g / i - mx);
}
}
cout << cnt << ' ' << ans << endl;
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
input:
3 5 10 7 79 1 7 1 2 1000000000 1 2 1 100 1000000000
output:
3 8 0 0 100 5050
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3564kb
input:
4 201 1000000000 1 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5...
output:
0 0 1 1 0 0 0 0
result:
wrong answer 2nd lines differ - expected: '0 0', found: '1 1'