#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }
typedef int ll;
typedef long double ld;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
typedef pair<ll,ll>pi; typedef pair<ll,pi>spi; typedef pair<pi,pi>dpi;
#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (200006)
ll n,k,A[MAXN];
bitset<MAXN> taken;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
unordered_map<ll,ll,custom_hash> mp;
#define gc getchar_unlocked
void in(ll&x){
x=0;
char ch=gc();
while(ch<'0'||ch>'9')ch=gc();
while(ch>='0'&&ch<='9'){
x=(x<<3)+(x<<1)+ch-48;
ch=gc();
}
}
int main(){
FAST
in(n),in(k);
n+=k;
FOR(i,1,n)in(A[i]),mp[A[i]]=i;
auto tryy=[&](ll sum){
taken.reset();
ll co=0,other=0,mi=0;
FOR(i,1,n)if(!taken[i] && co<n-k && (mi==0||co+(mi-i)-((mi-i)&1)>=n-k)){
other=mp[sum-A[i]];
if(other>i) {
mi=other;
co+=2;
taken[i]=taken[other]=1;
}
}else break;
if(co==n-k)return 1;
else return 0;
};
if(n<4*k){
FOR(i,1,k+1)DEC(j,n,n-k)if(i<=j&&tryy(A[i]+A[j])){
FOR(i,1,n)if(taken[i])cout<<A[i]<<' ';cout<<'\n';
return 0;
}
}else{
unordered_map<ll,ll,custom_hash> mp;
FOR(i,1,2*k)DEC(j,n,n-2*k+1)++mp[A[i]+A[j]];
for(auto i:mp)if(i.s>=k&&tryy(i.f)){
FOR(i,1,n)if(taken[i])cout<<A[i]<<' ';cout<<'\n';
return 0;
}
}
assert(0);
}
Compilation message
tabletennis.cpp: In function 'int main()':
tabletennis.cpp:22:20: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
^
tabletennis.cpp:77:4: note: in expansion of macro 'FOR'
FOR(i,1,n)if(taken[i])cout<<A[i]<<' ';cout<<'\n';
^~~
tabletennis.cpp:77:42: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
FOR(i,1,n)if(taken[i])cout<<A[i]<<' ';cout<<'\n';
^~~~
tabletennis.cpp:22:20: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
^
tabletennis.cpp:84:4: note: in expansion of macro 'FOR'
FOR(i,1,n)if(taken[i])cout<<A[i]<<' ';cout<<'\n';
^~~
tabletennis.cpp:84:42: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
FOR(i,1,n)if(taken[i])cout<<A[i]<<' ';cout<<'\n';
^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
1536 KB |
Output is correct |
2 |
Correct |
64 ms |
8888 KB |
Output is correct |
3 |
Correct |
64 ms |
8888 KB |
Output is correct |
4 |
Correct |
74 ms |
8892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
8892 KB |
Output is correct |
2 |
Correct |
67 ms |
8892 KB |
Output is correct |
3 |
Correct |
66 ms |
8896 KB |
Output is correct |
4 |
Correct |
77 ms |
8888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
640 KB |
Output is correct |
2 |
Correct |
159 ms |
15372 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
81 ms |
12476 KB |
Output is correct |
5 |
Correct |
6 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
72 ms |
8992 KB |
Output is correct |
3 |
Correct |
67 ms |
8892 KB |
Output is correct |
4 |
Correct |
67 ms |
8888 KB |
Output is correct |
5 |
Correct |
65 ms |
8888 KB |
Output is correct |
6 |
Correct |
79 ms |
8888 KB |
Output is correct |
7 |
Correct |
65 ms |
8964 KB |
Output is correct |
8 |
Correct |
68 ms |
8892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
3728 KB |
Output is correct |
2 |
Correct |
344 ms |
34288 KB |
Output is correct |
3 |
Correct |
340 ms |
35440 KB |
Output is correct |
4 |
Correct |
316 ms |
32876 KB |
Output is correct |
5 |
Correct |
579 ms |
16056 KB |
Output is correct |
6 |
Correct |
92 ms |
10680 KB |
Output is correct |
7 |
Correct |
323 ms |
33288 KB |
Output is correct |
8 |
Correct |
312 ms |
33520 KB |
Output is correct |