Submission #689602

#TimeUsernameProblemLanguageResultExecution timeMemory
689602LucaLucaMTable Tennis (info1cup20_tabletennis)C++17
100 / 100
156 ms4688 KiB
#include <bits/stdc++.h> using namespace std; /** trebuie sa alegem n din n + k numere astfel incat a[1] + a[n] = a[2] + a[n-1] = ... = a[n/2] + a[n/2+1] a[1] + a[n] = a[2] + a[n-1] a[n] - a[n-1] = a[2] - a[1] a[n-1] - a[n-2] = a[3] - a[2] ... a[n/2+1] - a[n/2] = a[n] - a[n-1] n*k + nlogn? **/ int a[150401]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; int m = n + k; for (int i=1; i<=m; i++) cin >> a[i]; for (int i=1; i<=k+1; i++) /// O(k) { /// incercam sa fie a[i] cel mai mic element , a[j] cel mai mare for (int j=m; m-j+i-1 <= k; j--) /// O(k*k) { int sum = a[i] + a[j]; int l=i, r=j; int cnt = 0; while (l < r) { while (l < r && a[l] + a[r] > sum) r--; while (l < r && a[l] + a[r] < sum) l++; if (a[l] + a[r] != sum) { cnt = -1; break; } cnt++; l++; } if (cnt >= n/2) { cnt = n / 2; vector<int>ans; int l=i, r=j; while (l < r && cnt--) { while (l < r && a[l] + a[r] > sum) r--; while (l < r && a[l] + a[r] < sum) l++; ans.push_back(a[l]); ans.push_back(a[r]); l++, r--; } for (int i=0; i<n; i+=2) cout << ans[i] << ' '; reverse(ans.begin(), ans.end()); for (int i=int(ans.size()) & 1; i<ans.size(); i+=2) cout << ans[i] << ' '; return 0; } } } return 0; }

Compilation message (stderr)

tabletennis.cpp: In function 'int main()':
tabletennis.cpp:78:50: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |                 for (int i=int(ans.size()) & 1; i<ans.size(); i+=2)
      |                                                 ~^~~~~~~~~~~
#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...