QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#884088#9738. Make It DivisibleXJK404WA 1ms12004kbC++141.7kb2025-02-05 21:16:192025-02-05 21:16:22

Judging History

This is the latest submission verdict.

  • [2025-02-05 21:16:22]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 12004kb
  • [2025-02-05 21:16:19]
  • Submitted

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];
void solve() {
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>d[i];
		e[i]=d[i];
	}
	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];
		}
	}
	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];
		}
	}
	cout<<cnt<<' ';
	ll ans=0;
	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: 11872kb

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: 1ms
memory: 12004kb

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

result:

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