QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#795613 | #9738. Make It Divisible | Nlll# | WA | 1ms | 3704kb | C++20 | 1.4kb | 2024-11-30 22:08:19 | 2024-11-30 22:08:19 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,j,k) for(int i=j;i<=k;++i)
#define For(i,j,k) for(int i=j;i>=k;--i)
const int N = 5e4+111;
int a[N],b[N];
int c[N];
int gcd(int x,int y){
if(!x) return y;
if(!y) return x;
return gcd(y,x%y);
}
int ans[N];
int stk[N];
void sol(){
int n,k;
cin>>n>>k;
int mn = 1e9;
FOR(i,1,n) cin>>a[i],c[i] = a[i];
FOR(i,1,n-1){
mn=min(abs(a[i]-a[i+1]),mn);
}
sort(a+1,a+1+n);
FOR(i,1,n) b[i] = a[i]-a[1];
int d = 0;
FOR(i,1,n) d = gcd(d,b[i]);
int up = sqrt(d);
int num = 0;
if(d==0){
cout<<k<<' '<<1ll*k*(k+1)/2<<'\n';
return;
}
long long sum = 0;
int cnt = 0;
FOR(i,1,up){
if(d%i==0){
if(i>a[1]&&(i-a[1])<=min(k,mn)){
ans[++cnt] = i-a[1];
}
if(d!=i*i){
if(d/i>a[1]&&(d/i-a[1])<=min(k,mn)){
ans[++cnt] = d/i-a[1];
}
}
}
}
FOR(i,1,cnt){
int ys = 1;
FOR(j,1,n){
a[j] = c[j] + ans[i];
}
stk[stk[0]=1]=a[1];
FOR(j,2,n){
For(p,stk[0],1){
if(a[j]%stk[p]==0||stk[p]%a[j]==0){
;
}
else{
ys=0;break;
}
if(stk[p]>=a[j]) --stk[0];
}
stk[++stk[0]] = a[j];
if(ys==0) break;
}
if(ys){
sum+=ans[i];
++num;
}
}
cout<<num<<' '<<sum<<'\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
sol();
}
return 0;
}
/*
1
3 10000
9 89 99
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3664kb
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: 3704kb
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: 3608kb
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 78th lines differ - expected: '2 4', found: '0 0'