QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#819441#9738. Make It DivisibleTosakaUCW#WA 0ms3740kbC++202.3kb2024-12-18 15:38:032024-12-18 15:38:04

Judging History

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

  • [2024-12-18 15:38:04]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3740kb
  • [2024-12-18 15:38:03]
  • 提交

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

int ceil(int x, int y) { return x / y + (x % y != 0); }

void solve() {
    int n = read();
    int k = read();
    vector<int> a(n);
    for (auto &x : a) x = read();
    int d = 0;
    for (int i = 1; i < n; i++) d = std::gcd(d, a[i] - a[i - 1]);
    // cerr << d << '\n';

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

    int cnt = 0;
    int sum = 0;

    std::unordered_map<int, int> mp;

    auto check = [&](int tar) {
        for (auto &x : a) {
            int t = tar - x;
            if (1 <= t and t <= k) {
                if (mp[t]) continue;
                mp[t] = 1;
                sum += t, cnt++;
                // cout << x << " + " << t << " = " << tar << '\n';
                // cout << t << " is valid.\n";
            }
        }
    };

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

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

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

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

详细

Test #1:

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

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

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'