QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#855273#9738. Make It Divisibleucup-team3474WA 0ms3840kbC++231.3kb2025-01-12 17:06:382025-01-12 17:06:38

Judging History

你现在查看的是最新测评结果

  • [2025-01-12 17:06:38]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3840kb
  • [2025-01-12 17:06:38]
  • 提交

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;
}

詳細信息

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'