Submission #15213

#TimeUsernameProblemLanguageResultExecution timeMemory
15213jays분배 (kriii3_Q)C++14
0 / 24
0 ms3520 KiB
#include <cstdio> #include <vector> using namespace std; int N, K; int pw2[20]; vector<int> one, num[20], ans[65540]; void solve() { pw2[0] = 1; for (int i = 1; i < 20; i++) pw2[i] = pw2[i-1]*2; for (int i = 0; i <= 1; i++) one.push_back(i); int cursz = one.size(); while (cursz <= 65540) { for (int i = 0; i < cursz; i++) one.push_back(one[i]+1); cursz = one.size(); } int tone = 0; for (int i = 0; i < pw2[N]; i++) { tone += one[i]; num[one[i]].push_back(i); } int perbox = pw2[N]/pw2[K]; for (int i = 0; i < pw2[K]; i++) { int curone = tone/pw2[K]; for (int j = 0; j < perbox; j++) { for (int k = curone; k >= 0; k--) { if (!num[k].empty()) { ans[i].push_back(num[k].back()); num[k].pop_back(); curone -= k; break; } } } } for (int i = 0; i < pw2[K]; i++) { for (int j = 0; j < perbox; j++) printf("%d%c", ans[i][j], " \n"[j == perbox-1]); } } int main() { scanf("%d%d", &N, &K); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...