Submission #524828

#TimeUsernameProblemLanguageResultExecution timeMemory
524828maks007Table Tennis (info1cup20_tabletennis)C++14
100 / 100
144 ms6200 KiB
#include <bits/stdc++.h> using namespace std; #define break_it assert(false) #define int long long main(void) { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; vector <int> a(n+k); for(int i = 0; i < n +k; i ++) cin >> a[i]; function <void(int,int, int)> check2=[&](int sum, int start, int end) { vector <int> ans; ans.push_back(a[start-1]); ans.push_back(a[end+1]); int l = start, r = end; int cnt = 0; while(l < r) { if(cnt >= k) return; if(a[l] + a[r] == sum) { ans.push_back(a[l]); ans.push_back(a[r]); l ++; r --; }else if(a[l] + a[r] > sum) { r--; cnt ++; }else l ++, cnt ++; if(ans.size() >= n) break; } if(ans.size() == n) { sort(ans.begin(), ans.end()); for(auto i : ans) cout << i << " "; exit(0); } }; function <void(int, int, int)> solve=[&](int start, int end, int sm = 0) { vector <int> fors; int sum = 0; if(start == end and end == -1) sum = sm; else sum = a[start] + a[end]; int none = -1; int l = 0, r = n+k-1; while(l < r){ if(a[l] + a[r] > sum) { if(none != -1) return; none = r; r--; }else if(a[l] + a[r] < sum) { if(none != -1) return; none = l; l ++; } l ++; r --; } if(none == -1) { none = (n+k)/2; } for(int i = 0; i <= n+k-1; i ++) { if(none == i) continue; fors.push_back(a[i]); } for(auto i : fors) cout << i << " "; exit(0); }; if(k == 1) { solve(0, n+k-1, 0); solve(0, n+k-2, 0); solve(1, n+k-1, 0); return 0; } map <int,int> mp; vector <int> candidate; for(int i = 0; i <= k; i ++) { for(int j = i+n-1; j < n+k; j ++) { check2(a[i] + a[j], i+1, j-1); } } return false; }

Compilation message (stderr)

tabletennis.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    6 | main(void) {
      | ^~~~
tabletennis.cpp: In lambda function:
tabletennis.cpp:31:18: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   31 |    if(ans.size() >= n) break;
      |       ~~~~~~~~~~~^~~~
tabletennis.cpp:33:17: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   33 |   if(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...