제출 #299641

#제출 시각아이디문제언어결과실행 시간메모리
299641E869120Table Tennis (info1cup20_tabletennis)C++14
43 / 100
63 ms3948 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 map<long long, int> Map; vector<long long> Cand, Cand2; for (int i = 0; i < (K + 2) * 20; i++) { int t1 = 1000000, t2 = 1000000; while (t2 < 0 || t2 >= N + K) { t1 = rand() % (N + K); t2 = (N - 1 - t1) + (rand() % (2 * K + 1)); } int val = A[t1] + A[t2]; Map[val] += 1; Cand2.push_back(val); } sort(Cand2.begin(), Cand2.end()); Cand2.erase(unique(Cand2.begin(), Cand2.end()), Cand2.end()); for (int i = 0; i < Cand2.size(); i++) { //cout << Cand2[i] << " " << Map[Cand2[i]] << endl; if (Map[Cand2[i]] >= 6) Cand.push_back(Cand2[i]); } // 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; }

컴파일 시 표준 에러 (stderr) 메시지

tabletennis.cpp: In function 'int main()':
tabletennis.cpp:49:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |  for (int i = 0; i < Cand2.size(); i++) {
      |                  ~~^~~~~~~~~~~~~~
tabletennis.cpp:55:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |  for (int i = 0; i < Cand.size(); i++) {
      |                  ~~^~~~~~~~~~~~~
tabletennis.cpp:62:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |   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...