Submission #423917

# Submission time Handle Problem Language Result Execution time Memory
423917 2021-06-11T14:08:40 Z oolimry Table Tennis (info1cup20_tabletennis) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int) (x).size()
#define all(x) (x).begin(), (x).end()
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define tern(cond, a, b) (cond ? a : b)
typedef long long lint;
typedef pair<int,int> ii;

int n, K;
vector<int> arr;
vector<ii> stuff;
vector<int> X;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	cin >> n >> K;
	n += K;
	arr.resize(n);
	for(int i = 0;i < n;i++) cin >> arr[i];
	
	
	for(register int i = K+1;i <= n-K-1;i++){
		int other = n-i;
		for(register int j = max(other-K-5,0);j <= min(n-1, other+K+5);j++){
			if(i != j) X.push_back(arr[i]+arr[j]);
		}
	}
	
	sort(all(X));
	for(int x : X){
		if(stuff.empty() or stuff.back().first != x) stuff.push_back(ii(x,1));
		else stuff.back().second++;
	}
	
	if(n > 2000 and k > 20) return 0;
	
	for(int s = 0;s <= K+1;s++){
		for(int e = n-1;e >= n-K-1;e--){
			if(s + (n-1)-e > K) continue;
			
			int str = arr[s]+arr[e];
			
			deque<int> ans;
			for(int i = s;i < K+1;i++){
				auto it = lower_bound(all(arr), str-arr[i]);
				if(it == arr.end()) continue;
				if(*it == str-arr[i] and arr[i] != str-arr[i]) ans.push_back(arr[i]);
			}
			
			for(int i = n-K;i <= e;i++){
				auto it = lower_bound(all(arr), str-arr[i]);
				if(it == arr.end()) continue;
				if(*it == str-arr[i] and arr[i] != str-arr[i]) ans.push_back(arr[i]);
			}
			
			auto it = lower_bound(all(stuff), ii(str, -1));
			int val = 0;
			if(it != stuff.end() and it->first == str) val = it->second;
			
			if(sz(ans) + val >= n-K){
				ans.clear();
				
				for(int i = s;i <= e;i++){
					auto it = lower_bound(all(arr), str-arr[i]);
					if(it == arr.end()) continue;
					if(*it == str-arr[i] and arr[i] != str-arr[i]) ans.push_back(arr[i]);
				}
				
				while(sz(ans) > n-K){
					ans.pop_front();
					ans.pop_back();
				}
				for(int x : ans) cout << x << " ";
				return 0;
			}
		}
	}
}

Compilation message

tabletennis.cpp: In function 'int main()':
tabletennis.cpp:26:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   26 |  for(register int i = K+1;i <= n-K-1;i++){
      |                   ^
tabletennis.cpp:28:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   28 |   for(register int j = max(other-K-5,0);j <= min(n-1, other+K+5);j++){
      |                    ^
tabletennis.cpp:39:18: error: 'k' was not declared in this scope
   39 |  if(n > 2000 and k > 20) return 0;
      |                  ^