QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#855273 | #9738. Make It Divisible | ucup-team3474 | WA | 0ms | 3840kb | C++23 | 1.3kb | 2025-01-12 17:06:38 | 2025-01-12 17:06:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
using ll = long long;
void solve() {
int n, k;
cin >> n >> k;
vector<int> b(n);
for (int i = 0; i < n; i ++) {
cin >> b[i];
}
int g = 0;
for (int i = 0; i + 1 < n; i ++) {
g = gcd(g, abs(b[i] - b[i + 1]));
}
if (!g) {
cout << k << ' ' << 1ll * k * (k + 1) / 2 << '\n';
return;
}
ll cnt = 0, sum = 0;
int mn = *min_element(all(b));
auto calc = [&](int x) {
if (x <= mn || x > mn + k) {
return;
}
int d = x - mn;
for (int i = 0; i + 1 < n; i ++) {
int p = b[i] + d;
int q = b[i + 1] + d;
if (p > q) {
swap(p, q);
}
if (q % p) {
return;
}
}
cnt ++;
sum += x - mn;
};
for (int i = 1; i * i <= g; i ++) {
if (g % i == 0) {
calc(i);
if (i * i != g) {
calc(g / i);
}
}
}
cout << cnt << ' ' << sum << '\n';
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
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: 3840kb
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: 3668kb
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'