Submission #299635

#TimeUsernameProblemLanguageResultExecution timeMemory
299635E869120Table Tennis (info1cup20_tabletennis)C++14
87 / 100
3012 ms4720 KiB
#include <bits/stdc++.h> using namespace std; int N, K; int A[1 << 18]; bool used[1 << 18]; bool solve(int border) { for (int i = 0; i < N + K; i++) used[i] = false; int cl = 0, cr = N + K - 1, cnt = 0; while (cl < cr && cnt < (N / 2)) { if (A[cl] + A[cr] > border) cr--; else if (A[cl] + A[cr] < border) cl++; else { used[cl] = true; used[cr] = true; cl += 1; cr -= 1; cnt += 1; } } if (cnt == (N / 2)) return true; return false; } int main() { // Step #1. Input scanf("%d%d", &N, &K); for (int i = 0; i < N + K; i++) scanf("%d", &A[i]); sort(A, A + (N + K)); // Step #2. BruteForce vector<long long> Cand; for (int i = 0; i <= K; i++) { for (int j = 0; j <= K - i; j++) { Cand.push_back(A[i] + A[N + K - 1 - j]); } } sort(Cand.begin(), Cand.end()); Cand.erase(unique(Cand.begin(), Cand.end()), Cand.end()); // Step #3. Tansaku for (int i = 0; i < Cand.size(); i++) { bool I = solve(Cand[i]); if (I == false) continue; vector<int> vec; for (int j = 0; j < N + K; j++) { if (used[j] == true) vec.push_back(A[j]); } for (int j = 0; j < vec.size(); j++) { if (j) printf(" "); printf("%d", vec[j]); } printf("\n"); return 0; } return 0; }

Compilation message (stderr)

tabletennis.cpp: In function 'int main()':
tabletennis.cpp:45:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |  for (int i = 0; i < Cand.size(); i++) {
      |                  ~~^~~~~~~~~~~~~
tabletennis.cpp:52:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |   for (int j = 0; j < vec.size(); j++) {
      |                   ~~^~~~~~~~~~~~
tabletennis.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |  scanf("%d%d", &N, &K);
      |  ~~~~~^~~~~~~~~~~~~~~~
tabletennis.cpp:31:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   31 |  for (int i = 0; i < N + K; i++) scanf("%d", &A[i]);
      |                                  ~~~~~^~~~~~~~~~~~~
#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...