Submission #365777

# Submission time Handle Problem Language Result Execution time Memory
365777 2021-02-12T10:41:43 Z tengiz05 Table Tennis (info1cup20_tabletennis) C++17
20 / 100
2739 ms 15212 KB
#include <bits/stdc++.h>
using namespace std;
//~ #define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
template<class T> bool chmin(T& a, const T& b) {return a>b? a=b, true:false;}
template<class T> bool chmax(T& a, const T& b) {return a<b? a=b, true:false;}
const int mod = 1e9+7, N = 2e5+5;
int msb(int val){return sizeof(int)*8-__builtin_clzll(val)-1;}
int n, m, k;
int a[N];
bool check(vector<int> &v){
	int n = v.size();
	int t = v[0] + v[n-1];
	for(int l=0,r=n-1;l<r;l++,r--){
		if(v[l] + v[r] != t)return false;
	}return true;
}
void solve(int test_case){
	int i, j;
	cin >> n >> k;
	m = n+k;
	for(i=1;i<=m;i++){
		cin >> a[i];
	}
	sort(a+1,a+m+1);
	if(k == 1){
		bool ok = true;
		int t = (a[1] + a[m-1]);
		for(int l=1,r=m-1;l<r;l++,r--){
			if(a[l] + a[r] != t)ok = false;
		}
		if(ok){
			for(i=1;i<=m-1;i++)cout << a[i] << ' ' ;
			cout << '\n';
			return;
		}
		ok = true;
		t = (a[2] + a[m]);
		for(int l=2,r=m;l<r;l++,r--){
			if(a[l] + a[r] != t)ok = false;
		}
		
		if(ok){
			for(i=2;i<=m;i++)cout << a[i] << ' ' ;
			cout << '\n';
			return;
		}
		t = a[1] + a[m];
		for(int l=2,r=m-1;l<r;l++,r--){
			if(a[l] + a[r] != t){
				vector<int> v;
				for(i=1;i<=m;i++){
					if(i==l)continue;
					v.pb(a[i]);
				}
				if(check(v)){
					for(auto x : v)cout << x << ' ' ;
					cout << '\n';
					return;
				}
				v.clear();
				for(i=1;i<=m;i++){
					if(i==r)continue;
					v.pb(a[i]);
				}
				if(check(v)){
					for(auto x : v)cout << x << ' ' ;
					cout << '\n';
					return;
				}
				assert(false);
			}
		}
	}else {
		mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
		shuffle(a+1,a+m+1, rng);
		map<int,int> possible_sums_not;
		int counted = 0;
		possible_sums_not[a[1] + a[m]]++;
		possible_sums_not[a[1] + a[m-1]]++;
		possible_sums_not[a[1] + a[m-2]]++;
		
		possible_sums_not[a[2] + a[m]]++;
		possible_sums_not[a[2] + a[m-1]]++;
		possible_sums_not[a[2] + a[m-2]]++;
		
		possible_sums_not[a[3] + a[m]]++;
		//~ possible_sums_not[a[3] + a[m-1]]++;
		//~ possible_sums_not[a[3] + a[m-2]]++;
		
		
		vector<pii> possible_sums;
		for(auto [x,y] : possible_sums_not)possible_sums.pb({y,x});
		sort(all(possible_sums));
		reverse(all(possible_sums));
		for(auto [no_need, sum] : possible_sums){
			map<int,int>cnt;
			for(i=1;i<=m;i++){
				cnt[a[i]]++;
			}
			int have = 0;
			vector<int> v;
			for(i=1;i<=m;i++){
				if(!cnt.count(a[i]) || cnt[a[i]] <= 0)continue;
				if(a[i] >= sum)continue;
				if(sum-a[i] == a[i]){
					if(cnt[sum - a[i]] > 1){
						cnt[sum - a[i]]--;
						cnt[a[i]]--;
						have++;
						v.pb(a[i]);
						v.pb(sum-a[i]);
					}
				}else if(cnt[sum - a[i]] > 0){
					cnt[sum - a[i]]--;
					cnt[a[i]]--;
					have++;
					v.pb(a[i]);
					v.pb(sum-a[i]);
				}
			}
			//~ cout << sum << ' ' << have << '\n';
			if(have >= n/2){
				sort(v.begin(), v.begin() + n);
				for(i=0;i<n;i++)cout << v[i] << ' ' ;
				cout << '\n';
				return;
			}
		}
	}
	return;
}
/*

4 1
2 4 8 6 10

*/
signed main(){
	FASTIO;
//~ #define MULTITEST 1
#if MULTITEST
	int _T;
	cin >> _T;
	for(int T_CASE = 1; T_CASE <= _T; T_CASE++)
		solve(T_CASE);
#else
	solve(1);
#endif
	return 0;
}




Compilation message

tabletennis.cpp: In function 'void solve(int)':
tabletennis.cpp:85:7: warning: unused variable 'counted' [-Wunused-variable]
   85 |   int counted = 0;
      |       ^~~~~~~
tabletennis.cpp:26:9: warning: unused variable 'j' [-Wunused-variable]
   26 |  int i, j;
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 876 KB Output is correct
2 Correct 36 ms 2540 KB Output is correct
3 Correct 36 ms 2412 KB Output is correct
4 Correct 35 ms 2412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2739 ms 15212 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -