Submission #524766

# Submission time Handle Problem Language Result Execution time Memory
524766 2022-02-10T01:00:00 Z maks007 Table Tennis (info1cup20_tabletennis) C++14
29 / 100
3000 ms 732388 KB
#include <bits/stdc++.h>
 
using namespace std;
 #define break_it assert(false)
int main(void) {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector <int> a(n+k);
	for(int i = 0; i < n +k; i ++) cin >> a[i];
	function <int(vector <int>)> check=[](vector <int> s) {
		int n = s.size();
		for(int i = 0; i < n; i ++) {
			int j = i + 1;
			if(j >= n or n - i - 1 < 0 or n - j - 1 < 0) break;
			if(s[i] + s[n-i-1] == s[j]+s[n-j-1]) continue;
			return 0;
		}
		return 1;
	};
	function <void(int, int, int)> solve=[&](int start, int end, int sm = 0) {
		vector <int> fors;
		int sum = 0;
		if(start == end and end == -1) sum = sm;
		else sum = a[start] + a[end];
		int none = -1;
		int l = 0, r = n+k-1;
		while(l < r){
			if(a[l] + a[r] > sum) {
				if(none != -1) return;
				none = r;
				r--;
			}else if(a[l] + a[r] < sum) {
				if(none != -1) return;
				none = l;
				l ++;
			}
			l ++;
			r --;
		}
		if(none == -1) {
			none = (n+k)/2;
		}
		for(int i = 0; i <= n+k-1; i ++) {
			if(none == i) continue;
			fors.push_back(a[i]);
		}
		for(auto i : fors) cout << i << " ";
		exit(0);
	};	
	if(n+k<=18) {
		for(int mask = 0; mask < (1 << (n+k)); mask ++) {	
			if(__builtin_popcount(mask) == n) {
				vector <int> v;
				for(int i = 0; i < n+k; i ++) {
					if((mask & (1 << i))!=0) {
						v.push_back(a[i]);
					}
				}
				if(check(v)) {
					for(int i = 0; i < v.size(); i ++) cout << v[i] << " ";
					return false;
				}
			}
		}
		return false;
	}else if(k == 1) {
		solve(0, n+k-1, 0);
		solve(0, n+k-2, 0);
		solve(1, n+k-1, 0);
	}else {
		map <int,int> mp;
		for(int i = 0; i < n+k; i ++) {
			for(int j = 0; j < n+k; j ++) {
				if(i == j) continue;
				mp[a[i]+a[j]] ++;
			}
		}
		pair <int,int> mx;
		for(auto i : mp) mx=  max(mx, {i.second, i.first});
		solve(-1, -1, mx.second);
	}
	return false;
}  

Compilation message

tabletennis.cpp: In function 'int main()':
tabletennis.cpp:62:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |      for(int i = 0; i < v.size(); i ++) cout << v[i] << " ";
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 956 KB Output is correct
2 Correct 27 ms 4604 KB Output is correct
3 Correct 26 ms 4468 KB Output is correct
4 Correct 26 ms 4544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3089 ms 732388 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 716 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 4556 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -