Submission #222141

# Submission time Handle Problem Language Result Execution time Memory
222141 2020-04-12T07:49:32 Z ryansee Table Tennis (info1cup20_tabletennis) C++14
72 / 100
3000 ms 455264 KB
#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 long long 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;
map<ll,ll> mp;
int main(){
	FAST
	cin>>n>>k;
	n+=k;
	FOR(i,1,n)cin>>A[i],mp[A[i]]=i;
	vector<ll> ppl;
	auto tryy=[&](ll a,ll b){
		ppl.clear();
		taken.reset();
		ll sum=A[a]+A[b];
		ppl.eb(A[a]), ppl.eb(A[b]);
		taken[a]=taken[b]=1;
		FOR(i,a+1,b-1)if(!taken[i])if(ppl.size()<n-k){
			if(mp[sum-A[i]]>i) {
				ppl.eb(A[i]), ppl.eb(sum-A[i]);
				taken[i]=taken[mp[sum-A[i]]]=1;
			}
		}
		if(ppl.size()==n-k)return 1;
		else return 0;
	};
	FOR(i,1,k+1)DEC(j,n,n-k){
		if(i<=j&&tryy(i,j)){
			sort(all(ppl));
			for(auto i:ppl) cout<<i<<' ';cout<<'\n';
			return 0;
		}
	}
	assert(0);
}

Compilation message

tabletennis.cpp: In lambda function:
tabletennis.cpp:44:43: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   FOR(i,a+1,b-1)if(!taken[i])if(ppl.size()<n-k){
                                 ~~~~~~~~~~^~~~
tabletennis.cpp:50:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(ppl.size()==n-k)return 1;
      ~~~~~~~~~~^~~~~
tabletennis.cpp: In function 'int main()':
tabletennis.cpp:56:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    for(auto i:ppl) cout<<i<<' ';cout<<'\n';
    ^~~
tabletennis.cpp:56:33: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
    for(auto i:ppl) cout<<i<<' ';cout<<'\n';
                                 ^~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 896 KB Output is correct
2 Correct 6 ms 768 KB Output is correct
3 Correct 6 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 2432 KB Output is correct
2 Correct 172 ms 34024 KB Output is correct
3 Correct 138 ms 24556 KB Output is correct
4 Correct 140 ms 24552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 235 ms 49892 KB Output is correct
2 Correct 175 ms 34036 KB Output is correct
3 Correct 281 ms 66028 KB Output is correct
4 Correct 171 ms 34028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1024 KB Output is correct
2 Correct 207 ms 22136 KB Output is correct
3 Correct 8 ms 1280 KB Output is correct
4 Correct 134 ms 26872 KB Output is correct
5 Correct 8 ms 1408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 11 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 61 ms 13816 KB Output is correct
3 Correct 13 ms 3072 KB Output is correct
4 Correct 59 ms 19192 KB Output is correct
5 Correct 12 ms 3072 KB Output is correct
6 Correct 17 ms 1792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Execution timed out 3109 ms 455264 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 6144 KB Output is correct
2 Execution timed out 3102 ms 414072 KB Time limit exceeded
3 Halted 0 ms 0 KB -