CSES - Putka Open 2020 – 2/5 - Results
Submission details
Task:Summat
Sender:mango_lassi
Submission time:2020-09-27 21:04:49 +0300
Language:C++ (C++11)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED12
#2ACCEPTED32
#3ACCEPTED56
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2, 3details
#2ACCEPTED0.01 s1, 2, 3details
#3ACCEPTED0.01 s1, 2, 3details
#4ACCEPTED0.01 s1, 2, 3details
#5ACCEPTED0.01 s1, 2, 3details
#6ACCEPTED0.01 s2, 3details
#7ACCEPTED0.01 s2, 3details
#8ACCEPTED0.01 s2, 3details
#9ACCEPTED0.01 s2, 3details
#10ACCEPTED0.01 s2, 3details
#11ACCEPTED0.01 s3details
#12ACCEPTED0.01 s3details
#13ACCEPTED0.09 s3details
#14ACCEPTED0.01 s3details
#15ACCEPTED0.02 s3details

Compiler report

input/code.cpp: In function 'std::vector<long long int> test(ll, std::vector<long long int>)':
input/code.cpp:12:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int i = 1; i < as.size(); ++i) {
                    ~~^~~~~~~~~~~
input/code.cpp:19:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (as.size() > n) return {};
       ~~~~~~~~~~^~~
input/code.cpp:23:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (as.size() < n) return {};
      ~~~~~~~~~~^~~
input/code.cpp: In function 'void solve()':
input/code.cpp:65:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    for (auto v : res) cout << v + minv << ' '; cout << '\n';
    ^~~
input/code.cpp:65:48: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
    for (auto v : res) cout << v + minv << ' '; cout << '\n';...

Code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = (ll)1e9 + 7;
vector<ll> test(ll n, vector<ll> bs) {
vector<ll> as = {0};
multiset<ll> expected;
for (ll v : bs) {
auto it = expected.find(v);
if (it == expected.end()) {
for (int i = 1; i < as.size(); ++i) {
expected.insert(as[i] + v);
}
as.push_back(v);
} else {
expected.erase(it);
}
if (as.size() > n) return {};
}
// Check validity
if (as.size() < n) return {};
for (int i = 0; i+1 < n; ++i) {
if (as[i] > as[i+1]) return {};
}
vector<ll> sums;
for (int i = 0; i < n; ++i) {
for (int j = i+1; j < n; ++j) {
sums.push_back(as[i] + as[j]);
}
}
sort(sums.begin(), sums.end());
if (sums != bs) return {};
return as;
}
void solve() {
int n;
cin >> n;
int m = n*(n-1) / 2;
vector<ll> bs(m);
for (ll& v : bs) cin >> v;
sort(bs.begin(), bs.end());
// If we were guaranteed that the minimum would be zero, the problem would be easy to solve
// Can we find the minimum value in some n^2 attempts? YES:
// Smallest value must equal bs[0] = as[0] + as[1]
// Second smallest must equal bs[1] = as[0] + as[2]
// Loop which value equals bs[2] = as[1] + as[2].
// -> At worst, the nth pair!
// Minimum is 2*bs[0] - bs[1] - bs[2]
// Subtract twice that from all values
for (int i = 2; i < n; ++i) {
ll minv = (bs[0] + bs[1] - bs[i]) / 2;
vector<ll> tmp = bs;
for (ll& v : tmp) v -= 2*minv;
auto res = test(n, tmp);
if (! res.empty()) {
for (auto v : res) cout << v + minv << ' '; cout << '\n';
return;
}
}
cout << "-1\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
}

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
5
2 2 2 2 2 2 2 2 2 2

correct output
1 1 1 1 1 

user output
1 1 1 1 1 

Test 2

Group: 1, 2, 3

Verdict: ACCEPTED

input
5
3 4 5 5 6 6 7 7 8 9

correct output
1 2 3 4 5 

user output
1 2 3 4 5 

Test 3

Group: 1, 2, 3

Verdict: ACCEPTED

input
5
5 6 6 6 9 9 9 10 10 10

correct output
1 4 5 5 5 

user output
1 4 5 5 5 

Test 4

Group: 1, 2, 3

Verdict: ACCEPTED

input
5
2 3 3 6 6 6 6 7 7 10

correct output
1 1 2 5 5 

user output
1 1 2 5 5 

Test 5

Group: 1, 2, 3

Verdict: ACCEPTED

input
5
4 5 5 5 5 6 6 6 7 7

correct output
2 2 3 3 4 

user output
2 2 3 3 4 

Test 6

Group: 2, 3

Verdict: ACCEPTED

input
20
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...

correct output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

user output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

Test 7

Group: 2, 3

Verdict: ACCEPTED

input
20
3 4 5 5 6 6 7 7 7 8 8 8 9 9 9 ...

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

Test 8

Group: 2, 3

Verdict: ACCEPTED

input
20
52 55 55 57 62 62 63 64 66 71 ...

correct output
1 51 54 54 56 61 61 62 63 65 7...

user output
1 51 54 54 56 61 61 62 63 65 7...

Test 9

Group: 2, 3

Verdict: ACCEPTED

input
20
25 30 31 32 36 39 40 41 45 45 ...

correct output
8 17 22 23 24 28 43 50 53 55 6...

user output
8 17 22 23 24 28 43 50 53 55 6...

Test 10

Group: 2, 3

Verdict: ACCEPTED

input
20
9 10 14 17 17 20 21 22 24 25 2...

correct output
1 8 9 13 16 19 30 32 38 40 43 ...

user output
1 8 9 13 16 19 30 32 38 40 43 ...

Test 11

Group: 3

Verdict: ACCEPTED

input
100
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...

correct output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

user output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
Truncated

Test 12

Group: 3

Verdict: ACCEPTED

input
100
3 4 5 5 6 6 7 7 7 8 8 8 9 9 9 ...

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...
Truncated

Test 13

Group: 3

Verdict: ACCEPTED

input
100
502824619 505239810 505668108 ...

correct output
1 502824618 505239809 50566810...

user output
1 502824618 505239809 50566810...
Truncated

Test 14

Group: 3

Verdict: ACCEPTED

input
100
17871832 41618648 51611938 538...

correct output
3939271 13932561 37679377 4989...

user output
3939271 13932561 37679377 4989...
Truncated

Test 15

Group: 3

Verdict: ACCEPTED

input
100
70588435 115481965 116040218 1...

correct output
5902586 64685849 109579379 110...

user output
5902586 64685849 109579379 110...
Truncated