QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#855876 | #9738. Make It Divisible | xueman | WA | 0ms | 3824kb | C++23 | 1.8kb | 2025-01-13 12:01:30 | 2025-01-13 12:01:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
void print() { cout << '\n'; }
template <typename T, typename...Args>
void print(T t, Args...args) { cout << t << ' '; print(args...); }
using ll = long long;
const int N = 200010;
int dir[4][2] = {
{1, 0}, {0, 1}, {-1, 0}, {0, -1}
};
template <typename T> bool chmax(T &x, T y) { if (y > x) { x = y; return true; } return false; }
template <typename T> bool chmin(T &x, T y) { if (y < x) { x = y; return true; } return false; }
template <typename T = int>
vector<T> readVector(int n) {
vector<T> a(n);
for(T &x: a) cin >> x;
return a;
}
void solve () {
int n, k;
cin >> n >> k;
auto a = readVector(n);
int ans = 0;
ll sum = 0;
int g = 0;
int mn = *min_element(all(a));
for (int i = 0; i + 1 < n; i ++) {
g = gcd(g, abs(a[i] - a[i + 1]));
}
if (!g) {
cout << k << ' ' << 1ll * k * (k + 1) / 2 << '\n';
return;
}
auto work = [&](int t) {
int x = t - mn;
if (x < 1 || x > k) {
return;
}
for (int i = 0; i + 1 < n; i ++) {
int p = a[i] + x;
int q = a[i + 1] + x;
if (p > q) {
swap(p, q);
}
if (q % p) {
return;
}
}
ans ++;
sum += x;
};
for (int i = 1; i * i <= g; i ++) {
if (g % i == 0) {
work(i);
if (i * i != g) {
work(g / i);
}
}
}
cout << ans << ' ' << sum << '\n';
}
int main() {
ios::sync_with_stdio(0);
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: 3560kb
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: 3824kb
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'