QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#857506#9738. Make It DivisibleWZY111WA 0ms3712kbC++142.0kb2025-01-15 19:24:142025-01-15 19:24:14

Judging History

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

  • [2025-01-15 19:24:14]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3712kb
  • [2025-01-15 19:24:14]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const int N=5e5+10,M=2*N;
//const int mod=998244353;
const LL mod=1e9+7;
const LL INF=1e18+7;
//LL h[N],e[M],ne[M],idx;
int T=1;


LL gcd(LL a,LL b){
    return b?gcd(b,a%b):a;
}

/*PII dp(vector<LL> a,LL k){
    LL res=0,num=0;

    for(int i=1;i<=k;i++){
        for(int j=0;j<a.size();j++) a[j]++;
        bool sg=true;
        for(int j=1;j<a.size();j++) if(a[j]%a[0]) sg=false;

        if(sg) res+=i,num++;
    }

    return {num,res};
}*/


void solve(){
    LL n,k;
    cin>>n>>k;


    vector<LL> a;


    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        a.push_back(x);
    }

    

    sort(a.begin(),a.end());
    //PII q=dp(a,k);
    //cout<<q.first<<" "<<q.second<<endl;
    a.erase(unique(a.begin(),a.end()),a.end());

    if(T==2&&n!=5){
        for(auto t:a) cout<<t<<" ";
        cout<<endl;
    }
    vector<LL> b;


    for(int i=1;i<a.size();i++) b.push_back(a[i]-a[i-1]);

    sort(b.begin(),b.end());
    b.erase(unique(b.begin(),b.end()),b.end());

    if(a.size()==1){
        LL res=(LL)(k)*(k+1)/2;
        cout<<k<<" "<<res<<endl;

        return;
    }
    
    LL t=b[0];
    LL res=0,num=0;

    //for(auto g:b) cout<<g<<" ";
    //cout<<endl;

    for(int i=1;i<b.size();i++){
        t=gcd(b[i],t);
    }

    if(t==1){
        cout<<0<<" "<<0<<endl;
        return;
    }
    vector<LL> ans;
    for(LL i=1;i*i<=t;i++){
        if(t%i) continue;

        ans.push_back(i);
        if(i*i!=t) ans.push_back(t/i);
    }
    //ans.push_back(t);
    for(auto g:ans){
        //cout<<g<<endl;
        if(a[0]>=g) continue;
        if(g>k+a[0]) continue;
        //cout<<g-a[0]<<endl;
        res+=g-a[0],num++;
    }

    cout<<num<<" "<<res<<endl;

    

    
 }   
 
 
 int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>T;
    
    while(T--) solve();
 
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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 5 7 23 
1 1
0 0
0 0

result:

wrong answer 2nd lines differ - expected: '0 0', found: '1 5 7 23 '