QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#746430#9738. Make It Divisiblethe_fool#WA 0ms3784kbC++202.4kb2024-11-14 14:36:402024-11-14 14:36:42

Judging History

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

  • [2024-11-27 18:44:44]
  • hack成功,自动添加数据
  • (/hack/1263)
  • [2024-11-14 14:36:42]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3784kb
  • [2024-11-14 14:36:40]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;

using LL = long long;


struct dsu {
    int n;
    vector<int> fa;
    vector<int> mn;

    dsu(int _n, vector<int>& v) {
        n = _n;
        fa.assign(n + 1, 0);
        iota(fa.begin(), fa.end(), 0);
        mn=v;
    }

    int find(int x) {
        if (x == fa[x]) {
            return x;
        }
        return fa[x] = find(fa[x]);
    }

    void un(int x, int y) {
        x = find(x), y = find(y);
        fa[x] = y;
        mn[y] = mn[x];
    }
};
vector<int> pos;
vector<int> a;

bool check(int val) {
    // cerr<<val<<endl;
    vector<int> b(a);
    for(auto &v:b)v += val;
    dsu d(b.size(), b);
    for(auto p : pos) {
        if(p>0 && d.mn[d.find(p-1)]>=b[p]) {
            if(d.mn[d.find(p-1)] % b[p] == 0) {
                d.un(p,p-1);
            }
            else return false;
        }
        if(p+1<b.size() && d.mn[d.find(p+1)]>=b[p]) {
            if(d.mn[d.find(p+1)]%b[p] == 0) {
                d.un(p,p+1);
            }
            else return false;
        }
    }
    return true;
}

void solve() {
    int n,k;
    cin>>n>>k;
    a.resize(n);
    for(int i=0;i<n;i++) {
        cin>>a[i];
    }
    pos.resize(n);
    for(int i=0;i<n;i++)pos[i] = i;
    sort(pos.begin(),pos.end(),[&](int i1,int i2) {
        return a[i1] < a[i2];
    });
    int g = 0;
    for(int i=1;i<n;i++) {
        g = __gcd(g, a[pos[i]] - a[pos[0]]);
    }
    // cerr<<g<<endl;
    if(g == 0) {
        cout<<k<<' '<<k*(k+1)/2<<endl;
        return ;
    }
    // cerr<<g<<endl;
    int cnt = 0;
    int sum = 0;
    // set<int> s;
    for(int i=1;i*i<=g;i++) {
        if(g%i == 0) {
            if(i > a[pos[0]] && i-a[pos[0]] <= k) {
                // cerr<<' '<<i<<endl;
                if(check(i-a[pos[0]])) {
                    cnt++;
                    sum += i-a[pos[0]];
                }
                // s.insert(i);
            }
            if(g/i!=i&&g/i>a[pos[0]] && g/i-a[pos[0]]<=k) {
                if(check(g/i-a[pos[0]])) {
                    cnt++;
                    sum += g/i-a[pos[0]];
                }
            }
        }
    }
    cout<<cnt<<' '<<sum<<endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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'