QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#819838#9738. Make It DivisibleTosakaUCW#WA 0ms3700kbC++202.3kb2024-12-18 17:38:502024-12-18 17:38:51

Judging History

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

  • [2024-12-18 17:38:51]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3700kb
  • [2024-12-18 17:38:50]
  • 提交

answer

#include <bits/stdc++.h>
using i64 = long long;
#define int i64
#define pb push_back
#define ep emplace
#define eb emplace_back
using std::cerr;
// using namespace std::views;
// using namespace std::ranges;
using std::max, std::min, std::swap, std::array;
using std::cin, std::cout, std::string, std::vector;
using std::ostream;
int read(int x = 0, int f = 0, char ch = getchar()) {
    while (ch < 48 or 57 < ch) f = ch == 45, ch = getchar();
    while(48 <= ch and ch <= 57) x = x * 10 + ch - 48, ch = getchar();
    return f ? -x : x;
}
template <class T1, class T2> ostream &operator<<(ostream &os, const std::pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << '\n'; }
using pii = std::pair<double, double>;
#define fi first
#define se second

void solve() {
    int n = read();
    int k = read();
    vector<int> a(n);
    for (auto &x : a) x = read();
    int d = 0;

    std::sort(a.begin(), a.end());

    for (int i = 1; i < n; i++) {
        d = std::gcd(d, a[i] - a[i - 1]);
    }
    // cerr << d << '\n';

    int cnt = 0;
    int sum = 0;

    auto check = [&](int tar) {
        // cerr << tar << '\n';
        int t = tar - a[0];
        // int tar = a[0] + t;
        if (t < 1 or t > k) return;
        for (int i = 1; i < n; i++) {
            if ((a[i] + t) % tar != 0) {
                return;
            }
        }
        // cout << t << "is valid\n";
        sum += t, cnt++;
    };

    if (d == 0) {
        cnt = k;
        sum = (1LL + k) * k / 2LL;
        cout << cnt << ' ' << sum << '\n';
        return;
    }

    for (int i = 1; i <= d; i++) {
        // if (d % i == 0) {
        //     check(i);
        //     if (d / i != i) {
        //         check(d / i);
        //     }
        // }
        check(i);
    }

    cout << cnt << ' ' << sum << '\n';
}

signed main() {
    for (int T = read(); T--; solve());
    // solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3700kb

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: 3544kb

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'