이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll>a;
set<ll>st;
ll n, k;
bool put(ll l, ll r, ll cnt, ll left, vector<ll>deleted){
if(left < 0 || l >= n + k || r < 0 || l > r || !st.empty())
return false;
//cout << l << ' ' << r << ' ' << cnt << ' ' << left << endl;
while(l < r){
if(a[l] + a[r] != cnt){
if(a[l] + a[r] > cnt){
vector<ll>b = deleted;
vector<ll>c = deleted;
b.push_back(r);
c.push_back(l);
c.push_back(r);
return put(l, r - 1, cnt, left - 1, b) || put(l + 1, r - 1, cnt, left - 2, c);
}
else{
vector<ll>b = deleted;
vector<ll>c = deleted;
b.push_back(l);
c.push_back(l);
c.push_back(r);
return put(l + 1, r, cnt, left - 1, b)|| put(l + 1, r - 1, cnt, left - 2, c);
}
}
l++, r--;
}
if(deleted.size() == 2){
for(auto i: deleted)
st.insert(i);
return true;
}
return false;
}
int main(){
cin >> n >> k;
a.resize(n + k);
for(int i = 0; i < n + k; i++)
cin >> a[i];
ll sum = 0;
for(auto i: a)
sum += i;
sort(a.begin(), a.end());
if(n + k <= 18){
for(int mask = 0; mask < (1 << (n + k)); mask++){
ll cnt = 0, mn = 1e9, mx = -1, sum2 = sum;
map<ll, ll>mp;
for(int j = 0; j < n + k; j++){
if((mask >> j) % 2 != 0){
//cout << a[j] << ' ';
cnt++;
sum2 -= a[j];
}
else{
mn = min(mn, a[j]);
mx = max(mx, a[j]);
mp[a[j]]++;
}
}
// cout << endl;
if(cnt != k)
continue;
if(sum2 % (n / 2) != 0)
continue;
ll bl = sum2 / (n / 2);
//cout << "Look: " << sum2 << ' ' << bl << endl;
bool ok = false;
for(int j = 0; j < n + k; j++){
if((mask >> j )% 2 != 0)
bl = bl;
else{
if(mp[bl - a[j]] <= 0)
ok = true;
mp[bl - a[j]]--;
}
}
if(ok)
continue;
for(int j = 0; j < n + k; j++){
if((mask >> j) % 2 != 0)
bl = bl;
else
cout << a[j] << ' ';
}
cout << endl;
return 0;
}
}
if(k == 2){
if(put(0, n + k - 1, a[0] + a[n + k - 1], 2, {})){
for(int i = 0; i < n + k; i++){
if(!st.count(i))
cout << a[i] << ' ';
}
cout << endl;
}
else if(put(1, n + k - 1, a[1] + a[n + k - 1], 1, {0})){
for(int i = 0; i < n + k; i++){
if(!st.count(i))
cout << a[i] << ' ';
}
cout << endl;
}
else if(put(0, n + k - 2, a[0] + a[n + k - 2], 1, {n + k - 1})){
for(int i = 0; i < n + k; i++){
if(!st.count(i))
cout << a[i] << ' ';
}
cout << endl;
}
else if(put(1, n + k - 2, a[1] + a[n + k - 2], 0, {n + k - 1, 0})){
for(int i = 0; i < n + k; i++){
if(!st.count(i))
cout << a[i] << ' ';
}
cout << endl;
}
else if(put(2, n + k - 1, a[2] + a[n + k - 1], 0, {0, 1})){
for(int i = 0; i < n + k; i++){
if(!st.count(i))
cout << a[i] << ' ';
}
cout << endl;
}
else if(put(0, n + k - 3, a[0] + a[n + k - 3], 0, {n + k - 1, n + k - 2})){
for(int i = 0; i < n + k; i++){
if(!st.count(i))
cout << a[i] << ' ';
}
cout << endl;
}
/*
4 2
1 1 4 4 6 8
*/
return 0;
}
for(int i = 0; i < n + 1; i++){
ll sum2 = sum - a[i];
ll mn = a[0];
if(i == 0)
mn = a[1];
ll mx = a[n + k - 1];
if(i == n + k - 1)
mx = a[n + k - 2];
ll bl = sum2 / (n / 2);
if(sum2 % (n / 2) != 0)
continue;
if(mn + mx < bl || mx >= bl)
continue;
for(int j = 0; j < n + k; j++){
if(j == i)
continue;
cout << a[j] << ' ';
}
cout << endl;
return 0;
}
return 0;
}
# | 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... |