QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#855992#9738. Make It Divisibleshi2uku#WA 1ms3676kbC++141.7kb2025-01-13 14:23:432025-01-13 14:23:45

Judging History

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

  • [2025-01-13 14:23:45]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3676kb
  • [2025-01-13 14:23:43]
  • 提交

answer

#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    int mn = 0x3f3f3f3f;
    for (int i = 0; i < n; ++i) cin >> a[i], mn = min(mn, a[i]);
    ll l = mn + 1, r = mn + k;
    for (int i = 0; i < n; ++i) a[i] -= mn;
    int d = 0;
    for (int i = 1; i < n; ++i) d = __gcd(d, a[i]);
    vector<int> st;
    for (int i = 0; i < n; ++i) {
        while (st.size() && a[i] < st.front()) st.pop_back();
        if (st.size()) d = __gcd(d, a[i] - st.front());
        st.push_back(a[i]);
    }
    st.clear();
    for (int i = n - 1; i >= 0; --i) {
        while (st.size() && a[i] < st.front()) st.pop_back();
        if (st.size()) d = __gcd(d, a[i] - st.front());
        st.push_back(a[i]);
    }
    st.clear();
    if (d == 0) {
        int num = r - l + 1;
        ll sum = 1ll * num * (r + l) / 2;
        cout << num << " " << sum - 1ll * (l - 1) * num << '\n';
        return;
    }
    set<int> s;
    auto valid = [&](int x) -> bool {
        return x >= l && x <= r;
    };
    for (int i = 1; 1ll * i * i <= d; ++i) {
        if (d % i == 0) {
            if (valid(i)) s.insert(i);
            if (valid(d / i)) s.insert(d / i);
        }
    }
    ll sum = 0;
    for (auto u : s) sum += u;
    int num = s.size();
    cout << num << " " << sum - 1ll * (l - 1) * num << '\n';
}
int main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);
    int t;
    cin >> t;
    while (t--) solve();
}
/*
3
5 10
7 79 1 7 1
2 1000000000
1 2
1 100
1000000000
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3676kb

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

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'