# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
15360 | yukariko | 분배 (kriii3_Q) | C++98 | 1000 ms | 2040 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 <iostream>
#include <cstdio>
#include <vector>
#include <list>
using namespace std;
int a[16];
bool visit[1 << 16];
int N,K;
list<int> p[17];
bool end;
int sel[1<<16];
void solve(int pos, int depth, int cnt, int sum)
{
if(cnt == 0 && sum == 0)
{
for(int i=0; i < depth; i++)
{
cout << sel[i] << " ";
}
cout << "\n";
end = true;
return;
}
if(pos > N || cnt == 0 || sum < pos)
return;
if(p[pos].empty())
return solve(pos+1, depth, cnt, sum);
// no select
solve(pos+1, depth, cnt, sum);
if(end)
return;
// select
sel[depth] = p[pos].back();
p[pos].pop_back();
solve(pos, depth+1, cnt-1, sum - pos);
if(!end)
p[pos].push_back(sel[depth]);
}
int main()
{
cin >> N >> K;
a[0] = 0;
for(int i=1; i <= 16; i++)
a[i] = a[i-1] * 2 + (1 << (i-1));
int one_put = a[N] / (1 << K);
int n_put = 1 << (N-K);
for(int i=0, n = 1 << N; i < n; i++)
{
int count = 0;
for(int j = i; j; j >>= 1)
count += j & 1;
p[count].push_back(i);
}
for(int i=0, n = 1 << K; i < n; i++)
{
end = false;
solve(0, 0, n_put, one_put);
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |