Submission #365875

# Submission time Handle Problem Language Result Execution time Memory
365875 2021-02-12T13:17:25 Z amunduzbaev Table Tennis (info1cup20_tabletennis) C++14
87 / 100
617 ms 5860 KB
/** made by amunduzbaev **/
#include <bits/stdc++.h>
using namespace std;

#pragma GCC target ("avx,avx2,fma")
#pragma GCC optimize ("O3,unroll-loops")

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define NeedForSpeed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vv vector
#define int long long
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<ll> vll;
typedef vector<int> vii;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef pair<int, pii> ipii;
typedef pair<pii, int> piii;
template<class T> bool umin(T& a, const T& b) {return a > b? a = b, true:false;}
template<class T> bool umax(T& a, const T& b) {return a < b? a = b, true:false;}
 
const int N = 2e5+5;
const int mod = 1e9+7;
const ll inf = 1e18;
const ld Pi = acos(-1);
 
#define MULTI 0	
 
int n, m, k, ans, res, a[N];

inline bool check(int s){
	int l = 0, r = m-1, res = 0;
	while(l < r){
		if(a[l] + a[r] == s) { res+=2, l++, r--; continue; }
		if(a[l] + a[r] > s) r--;
		else l++;
	}
	//cout<<s<<" "<<res<<"\n";
	if(res >= n){
		vii tt;
		int l = 0, r = m-1;
		while(l < r){
			if(a[l] + a[r] == s) { tt.pb(a[l]), tt.pb(a[r]), l++, r--; }
			else if(a[l] + a[r] > s) r--;
			else l++;
			if(sz(tt) >= n) break;
		}
		sort(all(tt));
		for(auto x:tt) cout<<x<<" ";
		cout<<"\n";
		return 1;
	}
	return 0;
}

inline int rd(){
	char r;
	int start = 0, ret=0;
	while(true){
		r=getchar();
		if((r-'0'<0 || r-'0'>9) && r!='-' && !start) continue;
		if((r-'0'<0 || r-'0'>9) && r!='-' && start) break;
		if(start)ret*=10;
		start=true;
		ret+=r-'0';
	} return ret;
}

void solve(int t_case){
	srand(time(NULL));
	n = rd(), k = rd();
	m = n+k;
	for(int i=0;i<m;i++) a[i] = rd();
	
	sort(a, a+m);
	
	if(n >= 18000 && k >= 15){
		int i = rand()%m;
		int ri = m-i-1;
		if(check(a[i] + a[ri])) return;
		
		for(int j=1;j<k;j++){
			if(check(a[i] + a[ri-j])) return;
			if(check(a[i] + a[ri+j])) return;
		}
	} else {
		map<int, int> mm;
		for(int i=0;i<=k;i++){
			for(int j=1;j<=k-i+1;j++){
				if(mm[a[i] + a[m-j]]) continue;
				mm[a[i] + a[m-j]] = 1;
				if(check(a[i] + a[m-j])) return;
			}
		}
	}
}

signed main(){
	NeedForSpeed
	if(!MULTI) {
		solve(1);
	} else {
		int t; cin>>t;
		for(int t_case = 1; t_case <= t; t_case++) solve(t_case);
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 388 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1008 KB Output is correct
2 Correct 35 ms 5368 KB Output is correct
3 Correct 33 ms 5220 KB Output is correct
4 Correct 33 ms 4452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 5220 KB Output is correct
2 Correct 36 ms 5860 KB Output is correct
3 Correct 35 ms 5860 KB Output is correct
4 Correct 33 ms 5732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 3 ms 620 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 620 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 51 ms 5860 KB Output is correct
3 Correct 41 ms 5732 KB Output is correct
4 Correct 36 ms 5732 KB Output is correct
5 Correct 38 ms 5732 KB Output is correct
6 Correct 33 ms 5860 KB Output is correct
7 Correct 41 ms 5732 KB Output is correct
8 Correct 33 ms 5732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 617 ms 5860 KB Output is correct
3 Incorrect 610 ms 2924 KB Unexpected end of file - int32 expected
4 Halted 0 ms 0 KB -