QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#758694 | #9738. Make It Divisible | fhq_treap# | WA | 1ms | 3680kb | C++23 | 1.1kb | 2024-11-17 19:22:37 | 2024-11-17 19:22:37 |
Judging History
answer
#include<iostream>
#include<vector>
#include<algorithm>
using std::cin,std::cout;
int n,k,b[50010],ls[50010],rs[50010];
int s[50010],*tp=s;
void solve(){
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>b[i];
if(std::all_of(b+1,b+n+1,[](int x){return x==b[1];})){
cout<<k<<' '<<(k+1ll)*k/2<<'\n';
return;
}
b[0]=-1;
*tp=0;
for(int i=1;i<=n;i++){
while(b[*tp]>=b[i])ls[i]=*tp--;
if(tp!=s)rs[*tp]=i;
*++tp=i;
}
std::vector<int> xs;
for(int i=1;i<=n;i++){
int x=0;
if(ls[i]&&b[ls[i]]!=b[i]) x=ls[i];
if(rs[i]&&b[rs[i]]!=b[i]) x=rs[i];
if(x){
int u=b[x]-b[i];
for(int r=1;r*r<=u;r++)if(u%r==0){
if(r-b[i]<=k&&b[i]<r) xs.push_back(r-b[i]);
if(u/r-b[i]<=k&&b[i]<u/r) xs.push_back(u/r-b[i]);
}
break;
}
}
int ans1=0;
long long ans2=0;
for(auto x:xs){
int book=1;
for(int i=1;book&&i<=n;i++){
if(ls[i]&&(b[ls[i]]-b[i])%(b[i]+x)!=0) book=0;
if(rs[i]&&(b[rs[i]]-b[i])%(b[i]+x)!=0) book=0;
}
if(book) ans1++,ans2+=x;
}
cout<<ans1<<' '<<ans2<<'\n';
}
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
int T;
cin>>T;
while(T--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
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: 3676kb
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: 3680kb
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'