# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
525071 | dron_rp | Table Tennis (info1cup20_tabletennis) | C++14 | 3085 ms | 5356 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, k;
vector<ll> a, ans;
map<pair<ll, ll>, bool> dp;
bool check(ll sum, ll items, ll W, vector<bool>&visited){
if (sum == W/2 && items == n/2){
return true;;
}
if (dp.count({sum, items})) return dp[{sum, items}];
dp[{sum, items}] = false;
}
bool good(vector<ll>v){
sort(v.begin(), v.end());
ll sum1 = 0, sum2 = 0;
for (int i = 0; i<n/2; i+=2){
sum1 += a[i]+a[n-1-i];
sum2 += a[i+1]+a[n-2-i];
}
return sum1 == sum2;
}
vector<ll> transform(vector<bool>&visited){
vector<ll> v(n);
int idx = 0;
for (int i = 0; i<n+k; i++){
if (visited[i]){
//cout << i << "\n";
v[idx++] = a[i];
}
}
return v;
}
void solve(vector<bool>&visited, int cnt){
if (cnt == k-1){
vector<ll> b = transform(visited);
if (good(b)){
ans = b;
}
return;
}
for (int i = 0; i<n+k; i++){
if (visited[i]){
visited[i] = false;
solve(visited, cnt+1);
visited[i] = true;
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> k;
a.resize(n+k);
for (auto& i : a) cin >> i;
vector<ll> v = a;
vector<bool> visited(n+k, true);
solve(visited, 0);
for (auto& i : ans) cout << i << " ";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |