제출 #638682

#제출 시각아이디문제언어결과실행 시간메모리
638682Dec0DeddTable Tennis (info1cup20_tabletennis)C++14
100 / 100
487 ms45612 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; const int N = 2e5+10; const int K = 400; int a[N], n, k, sz; gp_hash_table<int, bool> m; int num(int s) { int res=0; for (int i=1; i<=sz; ++i) { if (2*a[i] == s || m.find(s-a[i]) == m.end()) continue; ++res; } return res; } vector<int> gen(int s) { vector<int> res; int p=0; for (int i=1; i<=sz; ++i) { if (2*a[i] == s || m.find(s-a[i]) == m.end()) continue; res.push_back(a[i]), res.push_back(s-a[i]); p+=2; if (p == n) break; } return res; } int main() { cin>>n>>k; sz=n+k; for (int i=1; i<=sz; ++i) cin>>a[i]; for (int i=1; i<=sz; ++i) m[a[i]]=true; vector<int> x; if (sz <= 5*K) { bool ok=false; for (int i=1; i<=sz && !ok; ++i) { for (int j=i+1; j<=sz && !ok; ++j) { if (num(a[i]+a[j]) >= n) { x=gen(a[i]+a[j]); ok=true; break; } } } } else { gp_hash_table<int, int> cnt; for (int i=1; i<=2*k+1; ++i) { for (int j=n-k-1; j<=sz; ++j) ++cnt[a[i]+a[j]]; } for (auto u : cnt) { if (u.second >= k) { if (num(u.first) >= n) { x=gen(u.first); break; } } } } sort(x.begin(), x.end()); assert((int)x.size() >= n); for (auto u : x) cout<<u<<" "; cout<<"\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...