QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#783717#9738. Make It Divisible5720226849WA 1ms3768kbC++232.2kb2024-11-26 11:30:412024-11-26 11:30:41

Judging History

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

  • [2024-11-27 18:44:44]
  • hack成功,自动添加数据
  • (/hack/1263)
  • [2024-11-26 11:30:41]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3768kb
  • [2024-11-26 11:30:41]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'
const ll inf = 1e17;
const ll mod = 998244353;

vector<ll> get_divisors(ll n) {
    ll limit = 0;
    vector<ll> result;
    limit = floor(sqrt(n));
    for (ll i = 1; i <= limit; ++i)
        if (n % i == 0)
            result.push_back(i);
    for (ll i = (ll)result.size() - 1; i >= 0; --i)
        if (result[i] * result[i] < n)
            result.push_back(n / result[i]);
    return result;
}

void oper(ll testcase) {
    ll n = 0, k = 0, sum = 0;
    bool has_valid_x = false;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll i = 0; i < n; ++i)
        cin >> a[i];
    vector<ll> prefix_diff_gcd(n);
    prefix_diff_gcd[0] = 0;
    for (ll i = 1; i < n; ++i)
        prefix_diff_gcd[i] = gcd(prefix_diff_gcd[i - 1], abs(a[i] - a[i - 1]));
    vector<ll> valid_x;
    for (ll i = 1; i < n; ++i) {
        vector<ll> current_valid_x;
        if (a[i] == a[i - 1])
            continue;
        for (ll divisor : get_divisors(abs(a[i] - a[i - 1]))) {
            ll x = 0;
            x = divisor - a[i - 1];
            if (x >= 1 && x <= k && (a[i] + x) % (a[i - 1] + x) == 0)
                current_valid_x.push_back(x);
        }
        for (ll divisor : get_divisors(gcd(prefix_diff_gcd[i - 1], abs(a[i] - a[i - 1])))) {
            ll x = 0;
            x = divisor - a[i];
            if (x >= 1 && x <= k && (a[i - 1] + x) % (a[i] + x) == 0)
                current_valid_x.push_back(x);
        }
        if (has_valid_x)
            valid_x.resize(set_intersection(valid_x.begin(), valid_x.end(), current_valid_x.begin(), current_valid_x.end(), valid_x.begin()) - valid_x.begin());
        else {
            valid_x = current_valid_x;
            has_valid_x = true;
        }
    }
    if (has_valid_x) {
        for (ll x : valid_x)
            sum += x;
        cout << valid_x.size() << ' ' << sum;
    } else
        cout << k << ' ' << k * (k + 1) / 2;
    cout << '\n';
}

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    ll ttt = 1;
    cin >> ttt;
    for (ll i = 1; i <= ttt; i++) {
        oper(i);
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 0ms
memory: 3616kb

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
0 0
0 0
0 0

result:

ok 4 lines

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3768kb

input:

500
4 1000000000
8 14 24 18
4 1000000000
17 10 18 14
4 1000000000
6 17 19 19
4 1000000000
15 14 15 25
4 1000000000
16 16 5 25
4 1000000000
4 30 20 5
4 1000000000
11 4 23 9
4 1000000000
14 25 13 2
4 1000000000
18 18 1 15
4 1000000000
22 22 22 28
4 1000000000
15 17 17 10
4 1000000000
22 14 13 25
4 100...

output:

0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
...

result:

wrong answer 178th lines differ - expected: '1 2', found: '0 0'