제출 #835008

#제출 시각아이디문제언어결과실행 시간메모리
835008alex_2008Table Tennis (info1cup20_tabletennis)C++14
100 / 100
518 ms5692 KiB
#include <iostream> #include <algorithm> #include <vector> #define int long long using namespace std; const int N = 15e4 + 410; int a[N]; signed main() { srand(time(0)); int n, k; cin >> n >> k; for (int i = 1; i <= n + k; i++) { cin >> a[i]; } sort(a + 1, a + n + k + 1); if (n * k * k <= 240000000) { for (int i = 1; i <= k + 1; i++) { for (int j = n + k; j >= i + n - 1; j--) { int sm = a[i] + a[j], cnt = 0; int k1 = i, k2 = j; while (k1 < k2) { if (a[k1] + a[k2] == sm) { cnt++; k1++; k2--; } else if (a[k1] + a[k2] > sm) { k2--; } else k1++; } if (cnt >= (n / 2)) { k1 = i; k2 = j; vector <int> v; while (k1 < k2) { if (a[k1] + a[k2] == sm) { if (v.size() != n) { v.push_back(a[k1]); v.push_back(a[k2]); } cnt++; k1++; k2--; } else if (a[k1] + a[k2] > sm) { k2--; } else k1++; } sort(v.begin(), v.end()); for (auto it : v) { cout << it << " "; } cout << "\n"; return 0; } } } } else { while (1) { int i = rand() % (n / 2) + 1; for (int j = min(n + k, n + 2 * k + 1 - i); j >= (n + 1 - i); j--) { int sm = a[i] + a[j]; int k1 = 1, k2 = n + k, cnt = 0; while (k1 < k2) { if (a[k1] + a[k2] == sm) { cnt++; k1++; k2--; } else if (a[k1] + a[k2] > sm) { k2--; } else k1++; } if (cnt >= (n / 2)) { k1 = 1; k2 = n + k; vector <int> v; while (k1 < k2) { if (a[k1] + a[k2] == sm) { if (v.size() != n) { v.push_back(a[k1]); v.push_back(a[k2]); } cnt++; k1++; k2--; } else if (a[k1] + a[k2] > sm) { k2--; } else k1++; } sort(v.begin(), v.end()); for (auto it : v) { cout << it << " "; } cout << "\n"; return 0; } } } } }

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

tabletennis.cpp: In function 'int main()':
tabletennis.cpp:38:42: 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]
   38 |                             if (v.size() != n) {
      |                                 ~~~~~~~~~^~~~
tabletennis.cpp:83:42: 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]
   83 |                             if (v.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...