QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#864852 | #9738. Make It Divisible | coderjmc | WA | 0ms | 3712kb | C++14 | 1.1kb | 2025-01-21 09:54:34 | 2025-01-21 09:54:47 |
Judging History
answer
#include<iostream>
#include<utility>
#include<cstring>
#define int long long
#define endl "\n"
using namespace std;
const int N=5e4+5;
int a[N],n,k;
int st[N],top,lef[N],rig[N];
int cnt,sum;
void check(int x){
for(int i=1;i<=n;i++){
if(lef[i] && (a[lef[i]]+x)%(a[i]+x))return;
if(rig[i] && (a[rig[i]]+x)%(a[i]+x))return;
}
cnt++;
sum+=x;
}
signed main(){
cin.tie(0);cout.tie(0);
ios::sync_with_stdio(false);
int t;
cin>>t;
while(t--){
cin>>n>>k;
for(int i=1;i<=n;i++)cin>>a[i],lef[i]=rig[i]=0;
top=0;
for(int i=1;i<=n;i++){
while(top && a[st[top]]>a[i])top--;
lef[i]=rig[st[top]];
rig[st[top]]=i;
st[++top]=i;
}
int ll=1e18,rr=0,rt=st[1];
for(int i=1;i<=n;i++){
if(lef[i] && a[i]!=a[lef[i]])ll=a[i],rr=a[lef[i]];
if(rig[i] && a[i]!=a[rig[i]])ll=a[i],rr=a[rig[i]];
}
if(ll==1e18){
cout<<k<<" "<<(k+1)*k/2<<endl;
continue;
}
int x=rr-ll;cnt=sum=0;
for(int i=1;i*i<=x;i++){
if(x%i==0){
if(i<=k && i>ll)check(i-ll);
if(i*i!=x && x/i<=k && x/i>ll)check(x/i-ll);
}
}
cout<<cnt<<" "<<sum<<endl;
}
}
详细
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: 0
Accepted
time: 0ms
memory: 3584kb
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: 0ms
memory: 3712kb
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'