QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#884251 | #9738. Make It Divisible | XJK404 | WA | 3ms | 18340kb | C++14 | 2.2kb | 2025-02-05 22:49:55 | 2025-02-05 22:49:56 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define tin int
#define nit int
#define longlong long long
typedef long long ll;
typedef unsigned long long ull;
ll n,k;
ll a[1145141],cnt,flag,b[1145141],c[1145141],d[1145141],e[1145141],l[1145141],r[1145141],stac[1145141];
void solve() {
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>d[i];
e[i]=d[i];
l[i]=0;
r[i]=0;
}
r[n+1]=0;
sort(d+1,d+n+1);
ll m=0;
for(int i=1;i<=n;i++){
if(d[i]!=d[i-1]){
m++;
a[m]=d[i];
}
}
swap(n,m);
if(n<=1){
cout<<k<<' '<<k*(k+1)/2<<endl;
return ;
}
cnt=0;
ll cnt2=0;
ll sq=a[2]-a[1];
for(ll j=1;j<=ceil(sqrt(sq));j++){
ll C=sq/j;
if(C*j==sq){
if(C-a[1]>0&&k>=C-a[1]){
cnt2++;
c[cnt2]=C-a[1];
}
if(j-a[1]>0&&k>=j-a[1]){
cnt2++;
c[cnt2]=j-a[1];
}
}
}
sort(c+1,c+cnt2+1);
for(int j=1;j<=cnt2;j++){
if(c[j]!=c[j-1]){
cnt++;
b[cnt]=c[j];
}
}
for(int i=1;i<n;i++){
cnt2=0;
for(int j=1;j<=cnt;j++){
ll mi=a[1],ma=a[i+1];
if((ma+b[j])%(mi+b[j])==0){
cnt2++;
c[cnt2]=b[j];
}
}
cnt=0;
for(int j=1;j<=cnt2;j++){
cnt++;
b[cnt]=c[j];
}
}
ll top=0;
for(int i=1;i<=m;i++)
{
while(top&&e[stac[top]]>e[i]) l[i]=stac[top--];
if(stac[top]) r[stac[top]]=i;
stac[++top]=i;
}
for(int i=1;i<=n;i++){
cnt2=0;
for(int j=1;j<=cnt;j++){
ll mi=e[i];
if((max(mi,e[l[i]])+b[j])%(mi+b[j])==0&&(max(mi,e[r[i]])+b[j])%(mi+b[j])==0&&(max(e[l[i]],mi)-mi)%(e[i]+b[j])==0&&(max(e[r[i]],mi)-mi)%(e[i]+b[j])==0){
cnt2++;
c[cnt2]=b[j];
}
}
cnt=0;
for(int j=1;j<=cnt2;j++){
cnt++;
b[cnt]=c[j];
}
}
for(int i=1;i<m;i++){
cnt2=0;
for(int j=1;j<=cnt;j++){
ll mi=min(e[i],e[i+1]),ma=max(e[i],e[i+1]);
if((ma+b[j])%(mi+b[j])==0){
cnt2++;
c[cnt2]=b[j];
}
}
cnt=0;
for(int j=1;j<=cnt2;j++){
cnt++;
b[cnt]=c[j];
}
}
ll ans=0;
cout<<cnt<<' ';
for(int i=1;i<=cnt;i++){
ans+=b[i];
}
cout<<ans<<endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int T;
T = 1;
cin >> T;
while(T--) {
solve();
}
return 0;
}
/*
4
2 1000000000
1 2
1 100
1000000000
5 100
7 79 1 7 1
6 10000
1 4 10 13 23 33
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 18148kb
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: 18008kb
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: 0
Accepted
time: 0ms
memory: 18020kb
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:
ok 500 lines
Test #4:
score: -100
Wrong Answer
time: 3ms
memory: 18340kb
input:
1 50000 1000000000 230 286458 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 ...
output:
1 96
result:
wrong answer 1st lines differ - expected: '0 0', found: '1 96'