CSES - Putka Open 2020 – 2/5 - Results
Submission details
Task:Torni
Sender:kluopaja
Submission time:2020-09-26 21:20:39 +0300
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.01 s1, 2, 3details
#2--2, 3details
#3--3details

Compiler report

input/code.cpp: In function 'bool solve(std::vector<int>, int, std::vector<int>&)':
input/code.cpp:13:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i+1 < ans.size(); ++i) {
                    ~~~~^~~~~~~~~~~~
input/code.cpp: In function 'int main()':
input/code.cpp:36:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 2; i < b.size(); ++i) {
                  ~~^~~~~~~~~~
input/code.cpp:42:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < result.size(); ++i) {
                  ~~^~~~~~~~~~~~~~~

Code

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
bool solve(vector<int> b, int a1, vector<int>& out) {
  multiset<int> b_set(b.begin(), b.end());
  vector<int> ans;
  ans.push_back(a1);
  while(b_set.size()) {
    int b_smallest = *b_set.begin();
    ans.push_back(b_smallest - ans[0]);
    for(int i = 0; i+1 < ans.size(); ++i) {
      int x = ans[i] + ans.back();
      auto x_it = b_set.find(x);
      if(x_it == b_set.end()) {
        return false;
      }
      b_set.erase(x_it);
    }
  }
  out = ans;
  return true;
}
int main() {
  int n;
  cin>>n;
  vector<int> b;
  for(int i = 0; i < n*(n-1)/2; ++i) {
    int x;
    cin>>x;
    b.push_back(x);
  }
  sort(b.begin(), b.end());
  vector<int> result;
  for(int i = 2; i < b.size(); ++i) {
    int a1 = (b[0] + b[1] - b[i])/2;
    if(solve(b, a1, result)) {
      break;
    }
  }
  for(int i = 0; i < result.size(); ++i) {
    cout<<result[i]<<' ';
  }
  cout<<'\n';
}

Test details

Test 1

Group: 1, 2, 3

Verdict:

input
10
1
2
3
4
...

correct output
2
8
34
148
650
...

user output
(empty)

Test 2

Group: 2, 3

Verdict:

input
100
1
2
3
4
...

correct output
2
8
34
148
650
...

user output
(empty)

Test 3

Group: 3

Verdict:

input
100
996306
650655
896240
821967
...

correct output
87350005
606189151
122595036
193572715
227926807
...

user output
(empty)