Repository navigation
Expand file tree
/
Copy pathSilhouette.cpp
More file actions
89 lines (76 loc) · 1.59 KB
/
Copy pathSilhouette.cpp
File metadata and controls
89 lines (76 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
void solve(){
int n;
cin>>n;
vector<pair<int,int>> a;
vector<int> cnt;
vector<int> s;
for (int i =0;i<n;i++) {
int curr;
cin>>curr;
a.push_back({curr,i});
}
sort(a.begin(),a.end());
if (a[0].first!=0) {
cout<<-1<<endl;
return;
}
for (int i =0;i<a.size();) {
int j = i;
while (j< n && a[j].first == a[i].first) {
j++;
}
cnt.push_back(j -i);
s.push_back(a[i].first);
i= j;
}
int k = s.size();
vector<int> x(k);
if ( k ==1) {
x[0] = 1;
}else {
for (int i =0;i<k -1;i++) {
int now = s[i+1] - s[i];
if (now%cnt[i]!=0) {
cout<<-1<<endl;
return;
}
x[i] = now /cnt[i];
if (i > 0 && x[i] <= x[i - 1]) {
cout << -1 << endl;
return;
}
}
x[k - 1] = x[k - 2] + 1;
}
vector<int> ans(n);
int group = 0;
for (int i = 0; i < n; ) {
int j = i;
while (j < n && a[j].first == a[i].first) {
j++;
}
for (int p = i; p < j; p++) {
ans[a[p].second] = x[group];
}
group++;
i = j;
}
for (int i =0;i<ans.size();i++) {
cout<<ans[i]<<" ";
}
cout<<endl;
}
signed main () {
ios::sync_with_stdio(0);
cin.tie(0);
int T =1;
cin>>T;
while(T--){
solve();
}
return 0;
}