이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#ifdef ONLINE_JUDGE
const int MAXN = 2e5 + 10;
#endif
#ifndef ONLINE_JUDGE
const int MAXN = 1029;
#endif
const int MOD = 1e9 + 7;
#define ll __int128
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
ll read() { int x; cin >> x; return (ll)x; }
long long bm(long long b, long long p) {
if(p==0) return 1 % MOD;
long long r = bm(b, p >> 1);
if(p&1) return (((r*r) % MOD) * b) % MOD;
return (r*r) % MOD;
}
long long inv(long long b) {
return bm(b, MOD-2);
}
long long f[MAXN];
long long nCr(int n, int r) {
long long ans = f[n]; ans *= inv(f[r]); ans %= MOD;
ans *= inv(f[n-r]); ans %= MOD; return ans;
}
void precomp() { for(int i=0; i<MAXN; i++) f[i] = (i == 0 ? 1 % MOD : (f[i-1] * i) % MOD); }
int fastlog(int x) {
return (x == 0 ? -1 : 32 - __builtin_clz(x) - 1);
}
void gay(int i) { cout << "Case #" << i << ": "; }
void solve(int tc) {
int n, k; cin >> n >> k;
int a[n+k+1];
for(int i=1; i<=n+k; i++) {
cin >> a[i];
}
gp_hash_table<int, bool> yes;
for(int i=1; i<=n+k; i++) yes[a[i]] = 1;
vector<int> sums;
if(n + k <= 4000) {
for(int i=n; i<=n+k; i++) {
for(int j=1; j<=k+1; j++) {
if(j < i) sums.push_back(a[i] + a[j]);
}
}
}
else {
gp_hash_table<int, int> freq;
for(int i=0; i<44; i++) {
int x = rnd(1, n + k);
for(int j=1; j<=n+k; j++) {
if(j != x) {
freq[a[j] + a[x]]++;
if(freq[a[j] + a[x]] == 30) {
sums.push_back(a[j] + a[x]);
}
}
}
}
}
for(int x: sums) {
int ct = 0;
for(int i=1; i<=n+k; i++) {
if(a[i] * 2 == x) continue;
else if(yes[x - a[i]]) ct++;
}
if(ct >= n) {
vector<int> v;
int e = 0;
for(int i=1; i<=n+k; i++) {
if(a[i] * 2 == x) continue;
if(yes[x - a[i]]) {
v.push_back(a[i]);
v.push_back(x - a[i]);
e++;
if(e == n/2) break;
}
}
sort(v.begin(), v.end());
for(int x: v) cout << x << " ";
cout << "\n";
return;
}
}
}
int32_t main() {
precomp();
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; //cin >> t;
for(int i=1; i<=t; i++) solve(i);
}
// I don't know geometry.
// n = 13, k = 3: 0000001010000
// n = 13, k = 5: 0000010001000
// n = 13, k = 7: 0001000100010
// if k < n/2 and n odd: 1[010...10]111...1
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |