UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214432#2386. 回忆zhangxinyang111204ms2832kbC++111.1kb2024-11-18 21:09:482024-11-19 08:34:40

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,a[101],vis[200100],fla,b[101];
inline bool check(int num,int ind)
{
	for(int i=1;i<ind;i++) 
		if (!vis[num+a[i]]) return false;
	return true;
}
void dfs(int x,int lim,int a1){
	if (x>n){
		for (int i=1;i<=n;i++) cout<<a[i]<<" ";
		cout<<"\n";
		fla=1;
		return;
	}
	for (int i=lim;i<=n*(n-1)/2;i++)
		if (check(b[i]-a1,x))
		{
			a[x]=b[i]-a1;
			for (int j=1;j<x;j++)
				vis[a[x]+a[j]]--;
			dfs(x+1,i+1,a1);
			if (fla) break;
			for (int j=1;j<x;j++)
				vis[a[x]+a[j]]++;
		}
}
void work()
{
	memset(vis,0,sizeof(vis));
	fla=0;
	for (int i=1;i<=n*(n-1)/2;i++)
	{
		cin>>b[i];
		vis[b[i]]++;
	}
	if (n==2){
		if (b[1]!=0) cout<<0<<" "<<b[1]<<endl;
		return;
	}
	sort(b+1,b+n*(n-1)/2+1);
	for (int i=0;b[1]-i>i;i++)
	{
		a[1]=i; a[2]=b[1]-i; a[3]=b[2]-i;
		vis[b[1]]--; vis[b[2]]--;
		if (vis[a[2]+a[3]])
		{
			vis[a[2]+a[3]]--;
			dfs(4,3,a[1]);
			if(fla) break;
			vis[a[2]+a[3]]++;
		}
	}
}
signed main()
{
	cin.tie(nullptr) -> sync_with_stdio(false);
	cin>>n;
	work();
	return 0; 
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 2812kb

input:

5
4 5 9 9 10 13 14 14 15 19

output:

0 4 5 9 10 

result:

ok Your answer is correct.

Test #2:

score: 0
Wrong Answer
time: 0ms
memory: 2772kb

input:

5
5 9 9 10 12 12 13 16 17 17

output:


result:

wrong output format Unexpected end of file - int32 expected

Test #3:

score: 10
Accepted
time: 2ms
memory: 2816kb

input:

5
10 11 12 13 13 14 15 15 16 17

output:

4 6 7 8 9 

result:

ok Your answer is correct.

Test #4:

score: 0
Wrong Answer
time: 2ms
memory: 2828kb

input:

50
9 13 15 20 20 20 21 22 22 26 26 26 27 27 27 28 29 31 31 32 32 33 33 33 33 33 34 34 34 35 35 36 37...

output:

0 9 13 15 20 20 20 21 22 22 26 26 26 27 27 27 28 29 31 31 32 32 33 33 33 33 33 34 34 34 35 35 36 37 ...

result:

wrong answer Your answer is incorrect.

Test #5:

score: 0
Wrong Answer
time: 0ms
memory: 2832kb

input:

50
9 11 14 14 16 16 16 18 19 19 21 21 21 21 22 22 23 23 23 23 24 25 25 26 26 26 26 26 26 26 27 27 27...

output:

0 9 11 14 14 16 16 16 18 19 19 21 21 21 21 22 22 23 23 23 23 24 25 25 26 26 26 26 26 26 26 27 27 27 ...

result:

wrong answer Your answer is incorrect.

Test #6:

score: 0
Wrong Answer
time: 0ms
memory: 2832kb

input:

50
7 9 12 16 19 21 26 27 29 29 31 33 33 33 34 35 36 36 36 36 37 38 38 38 38 39 39 40 40 40 41 41 42 ...

output:

0 7 9 12 16 19 21 26 27 29 29 31 33 33 33 34 35 36 36 36 36 37 38 38 38 38 39 39 40 40 40 41 41 42 4...

result:

wrong answer Your answer is incorrect.

Test #7:

score: 0
Runtime Error

input:

300
660422 717145 1052261 1191442 1526558 1583281 1636913 1972029 2028752 2207583 2247577 2427928 25...

output:


result:


Test #8:

score: 0
Runtime Error

input:

300
1719032 1728175 1968715 2265775 2506315 2515458 2534303 2752316 3002166 3035709 3071903 3081046 ...

output:


result:


Test #9:

score: 0
Runtime Error

input:

300
725653 809390 819383 974701 984694 1058923 1068431 1068916 1152653 1317964 1422171 1432164 15159...

output:


result:


Test #10:

score: 0
Runtime Error

input:

300
2355315 3132486 3240117 3325566 3662015 3854305 3961936 4047385 4053636 4142315 4383834 4725290 ...

output:


result: