Submission #524837

#TimeUsernameProblemLanguageResultExecution timeMemory
524837boykutTable Tennis (info1cup20_tabletennis)C++14
58 / 100
3102 ms595652 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; vector<int> a(n + k); map<int, int> cnt; for (int i = 0; i < n + k; i++) { cin >> a[i]; } if (k == 1) { sort(a.begin(), a.end()); int sum = a[0] + a[n + k - 2], ok = 1; for (int l = 0, r = n + k - 2; l < r; l++, r--) { if (a[l] + a[r] != sum) ok = 0; } if (ok) { for (int i = 0; i < n + k - 1; i++) cout << a[i] << ' '; cout << '\n'; return 0; } sum = a[1] + a[n + k - 1], ok = 1; for (int l = 1, r = n + k - 1; l < r; l++, r--) { if (a[l] + a[r] != sum) ok = 0; } if (ok) { for (int i = 1; i < n + k; i++) cout << a[i] << ' '; cout << '\n'; return 0; } sum = a[0] + a[n + k - 1]; set<int> st(a.begin(), a.end()); deque<int> ans; for (int i = 0; i < n + k; i++) { if (st.count(sum - a[i])) { ans.push_back(a[i]); ans.push_back(sum - a[i]); st.erase(sum - a[i]); st.erase(a[i]); } } sort(ans.begin(), ans.end()); assert(ans.size() >= n); while (ans.size() > n) { ans.pop_back(); ans.pop_front(); } for (int v : ans) cout << v << ' '; return 0; } if (n > 2000 && k == 2) { sort(a.begin(), a.end()); deque<int> ans, ans2; auto check = [&](int sum, deque<int> & ans) ->int { set<int> st(a.begin(), a.end()); ans.clear(); for (int i = 0; i < n + k; i++) { if (st.count(sum - a[i])) { ans.push_back(a[i]); ans.push_back(sum - a[i]); st.erase(sum - a[i]); st.erase(a[i]); } } sort(ans.begin(), ans.end()); assert(ans.size() >= n); while (ans.size() > n) { ans.pop_back(); ans.pop_front(); } if (ans.size() == n) return 1; return 0; }; for (int i = 0; i <= k; i++) { for (int j = n - 1; j < n + k; j++) { if (check(a[i] + a[j], ans2)) { for (auto v : ans2) cout << v << ' '; return 0; } } } return 0; } for (int i = 0; i < n + k; i++) { for (int j = i + 1; j < n + k; j++) { cnt[a[i] + a[j]]++; } } int mx = -1, sum = -1; for (auto it : cnt) { if (it.second > mx) mx = it.second, sum = it.first; } assert(sum != -1); set<int> st(a.begin(), a.end()); deque<int> ans; for (int i = 0; i < n + k; i++) { if (st.count(sum - a[i])) { ans.push_back(a[i]); ans.push_back(sum - a[i]); st.erase(sum - a[i]); st.erase(a[i]); } } sort(ans.begin(), ans.end()); assert(ans.size() >= n); while (ans.size() > n) { ans.pop_back(); ans.pop_front(); } for (int v : ans) cout << v << ' '; return 0; }

Compilation message (stderr)

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from tabletennis.cpp:1:
tabletennis.cpp: In function 'int main()':
tabletennis.cpp:52:21: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   52 |   assert(ans.size() >= n);
      |          ~~~~~~~~~~~^~~~
tabletennis.cpp:53:21: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   53 |   while (ans.size() > n) {
      |          ~~~~~~~~~~~^~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from tabletennis.cpp:1:
tabletennis.cpp: In lambda function:
tabletennis.cpp:79:22: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   79 |    assert(ans.size() >= n);
      |           ~~~~~~~~~~~^~~~
tabletennis.cpp:80:22: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   80 |    while (ans.size() > n) {
      |           ~~~~~~~~~~~^~~
tabletennis.cpp:84:19: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   84 |    if (ans.size() == n) return 1;
      |        ~~~~~~~~~~~^~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from tabletennis.cpp:1:
tabletennis.cpp: In function 'int main()':
tabletennis.cpp:127:20: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  127 |  assert(ans.size() >= n);
      |         ~~~~~~~~~~~^~~~
tabletennis.cpp:128:20: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  128 |  while (ans.size() > n) {
      |         ~~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...