이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 15e4 + 10;
int atual[MAXN];
int v[MAXN];
int resp[MAXN];
bool FoundResp = false;
void bt(int id, int N, int K, int g1, int g2, int nG, int sG1, int sG2)
{
if (g1 > (N / 2) || g2 > (N / 2) || nG > K) return;
if (FoundResp) return;
if (id == N+K+1)
{
if (g1 != (N / 2) || g2 != (N / 2)) return;
if (sG1 != sG2) return;
for (int i = 1; i <= N + K; i++) resp[i] = atual[i];
FoundResp = true;
return;
}
atual[id] = 1;
bt(id+1, N, K, g1+1, g2, nG, sG1 + v[id], sG2);
bt(id+1, N, K, g1, g2+1, nG, sG1, sG2 + v[id]);
atual[id] = 0;
bt(id+1, N, K, g1, g2, nG+1, sG1, sG2);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, K;
cin >> N >> K;
for (int i = 1; i <= N + K; i++) cin >> v[i];
if (K == 0)
{
for (int i = 1; i <= N; i++) cout << v[i] << " ";
return 0;
}
bt(1, N, K, 0, 0, 0, 0, 0);
if (!FoundResp) {cerr << "BABAVAVAABCABC"; return 1;}
bool DaSpace = false;
for (int i = 1; i <= N+K; i++)
{
if (resp[i])
{
if (DaSpace) cout << " ";
DaSpace = true;
cout << v[i];
}
}
}
# | 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... |