제출 #735089

#제출 시각아이디문제언어결과실행 시간메모리
735089NintsiChkhaidzeTable Tennis (info1cup20_tabletennis)C++17
100 / 100
103 ms12728 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define s second #define int long long using namespace std; const int N = 2e5+5,inf = 1e9; int a[N],n,k; vector <int> v; void check(int sum){ v.clear(); int r = n + k; for (int i = 1; i <= n + k; i++){ while (i < r){ if (a[i] + a[r] > sum) { r--; continue; } break; } if (i < r && a[i] + a[r] == sum){ v.pb(a[i]),v.pb(a[r]); r--; } } if (v.size() == n){ sort(v.begin(),v.end()); for (int x: v) cout<<x<<" "; cout<<endl; exit(0); } } signed main (){ ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL); cin>>n>>k; for (int i = 1; i <= n+k;i++) cin>>a[i]; if (n <= 4*k){ for (int i = 1; i <= k+1; i++){ int c=0; for (int j = n + k; j > i; j--){ ++c; if (c > k+1) break; check(a[i] + a[j]); } } exit(0); } vector <int> vec; for (int i = 1; i <= 2*k; i++){ int c=0; for (int j = n + k; j > i; j--){ ++c; if (c > 2*k) break; vec.pb(a[i]+a[j]); } } sort(vec.begin(),vec.end()); int cnt=0; for (int i = 0; i < vec.size(); i++){ if (i && vec[i] != vec[i - 1]){ if (cnt >= k) check(vec[i - 1]); cnt=0; } ++cnt; } if (cnt >= k) check(vec.back()); } /* 6 1 1 3 4 5 6 8 431 */

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

tabletennis.cpp: In function 'void check(long long int)':
tabletennis.cpp:29:15: 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]
   29 |  if (v.size() == n){
      |      ~~~~~~~~~^~~~
tabletennis.cpp: In function 'int main()':
tabletennis.cpp:67:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |  for (int i = 0; i < vec.size(); 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...