UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214453#2386. 回忆naroto2022600ms1252kbC++1.1kb2024-11-18 22:12:382024-11-19 08:37:50

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#define ll long long
#define mp make_pair
using namespace std;
const int MN=305;
ll n,a[MN],sum[MN*MN];
multiset<ll> s;
multiset<ll>::iterator it;
void write(ll n){if(n<0){putchar('-');write(-n);return;}if(n>9)write(n/10);putchar(n%10+'0');}
ll read(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
bool check(ll x){
    a[1]=x;
    for(int i=2; i<=n; i++){
        a[i]=*s.begin()-a[1];
        for(int j=1; j<i; j++){
            it=s.find(a[j]+a[i]);
            if(it==s.end()) return false;
            s.erase(it);
        }
    }
    return true;
}
int main(){
    n=read();
    for(int i=1; i<=n*(n-1)/2; i++) sum[i]=read();
    sort(sum+1,sum+1+n*(n-1)/2);
    for(int i=0; i<=(sum[1]>>1); i++){
        s.clear();
        for(int j=1; j<=n*(n-1)/2; j++) s.insert(sum[j]);
        if(check(i)){
            for(int j=1; j<=n; j++) write(a[j]),putchar(' ');putchar('\n');
            return 0;
        }
    }
}

详细

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

Test #1:

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

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: 10
Accepted
time: 0ms
memory: 1180kb

input:

5
5 9 9 10 12 12 13 16 17 17

output:

1 4 8 8 9 

result:

ok Your answer is correct.

Test #3:

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

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: 10
Accepted
time: 0ms
memory: 1252kb

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:

1 8 12 14 19 19 20 21 25 25 26 31 33 34 35 37 38 40 43 44 47 48 50 52 52 52 54 54 54 55 55 57 61 68 ...

result:

ok Your answer is correct.

Test #5:

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

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:

2 7 9 12 12 14 14 16 20 20 21 23 24 24 24 25 28 29 30 35 35 38 38 38 41 42 44 44 47 51 55 55 56 57 5...

result:

ok Your answer is correct.

Test #6:

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

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 26 27 29 29 31 33 33 36 37 39 42 43 45 46 46 50 50 55 55 56 58 59 63 71 71 75 75 77 80 81 8...

result:

ok Your answer is correct.

Test #7:

score: 0
Time Limit Exceeded

input:

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

output:


result:


Test #8:

score: 0
Time Limit Exceeded

input:

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

output:


result:


Test #9:

score: 0
Time Limit Exceeded

input:

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

output:


result:


Test #10:

score: 0
Time Limit Exceeded

input:

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

output:


result: