Task: | Torni |
Sender: | mango_lassi |
Submission time: | 2020-09-27 21:04:37 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | WRONG ANSWER | 0 |
#2 | WRONG ANSWER | 0 |
#3 | WRONG ANSWER | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | WRONG ANSWER | 0.01 s | 1, 2, 3 | details |
#2 | WRONG ANSWER | 0.04 s | 2, 3 | details |
#3 | WRONG ANSWER | 0.04 s | 3 | details |
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 validityif (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 valuesfor (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: WRONG ANSWER
input |
---|
10 1 2 3 4 ... |
correct output |
---|
2 8 34 148 650 ... |
user output |
---|
-1 |
Test 2
Group: 2, 3
Verdict: WRONG ANSWER
input |
---|
100 1 2 3 4 ... |
correct output |
---|
2 8 34 148 650 ... |
user output |
---|
-1 |
Test 3
Group: 3
Verdict: WRONG ANSWER
input |
---|
100 996306 650655 896240 821967 ... |
correct output |
---|
87350005 606189151 122595036 193572715 227926807 ... |
user output |
---|
-1 |