QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#657796 | #6131. Tournament | kazimiyuuka | RE | 0ms | 4020kb | C++20 | 1.5kb | 2024-10-19 15:28:47 | 2024-10-19 15:28:47 |
Judging History
answer
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <random>
#include <cstdlib>
#include <numeric>
#include <functional>
#include <queue>
using namespace std;
using ll = long long;
ll mod = 1e9 + 7;
void slove()
{
int n, k;
cin >> n >> k;
// 可行构造方案数为2的因数个数次方 - 1;
int tmp = 0;
int tk = k;
while (tk % 2 == 0) {
tmp++;
tk /= 2;
}
if (n > (int)pow(2, tk) - 1) {
cout << "Impossible\n";
return;
}
vector<vector<int>> data(k + 1, vector<int>(n + 1));
int up = 1;
for (int i = 1; i <= k; i++) {
data[i][1] = i + 1;
if (i >= up) up *= 2;
for (int j = 2; j <= up; j *= 2) {
int rem = (data[i][1] - 1) % j;
if (rem >= j / 2) rem = -(j / 2);
else rem = j / 2;
int h = j / 2;
for (int m = j / 2 + 1; m <= j; m++) {
data[i][m] = data[i][m - h] + rem;
}
}
// 迭代到满
for (int j = 2; j * up <= n; j++) {
int diff = (j - 1) * up;
for (int m = 1; m <= up; m++) {
data[i][m + diff] = data[i][m] + diff;
}
}
}
for (int i = 1; i <= k; i++) {
for (int j = 1; j <= n; j++) {
cout << data[i][j] << " ";
}
cout << "\n";
}
return;
}
int main()
{
//freopen("out.txt", "w", stdout);
//freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int cnt = 1;
cin >> cnt;
while (cnt--)
{
slove();
}
};
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 4020kb
input:
2 3 1 4 3
output:
Impossible 2 1 4 3 3 4 1 2 4 3 2 1
result:
ok 4 lines
Test #2:
score: -100
Runtime Error
input:
100 1 4 2 1 2 2 2 3 3 6 4 2 4 3 4 4 4 5 5 4 6 1 6 2 6 4 7 1 8 3 8 7 8 8 8 14 9 4 10 1 10 2 10 3 12 2 12 3 12 4 12 8 13 2 14 1 14 2 14 4 15 4 16 9 16 15 16 16 16 28 17 6 18 1 18 2 18 4 19 5 20 1 20 3 20 4 20 6 21 1 22 1 22 2 22 3 23 4 24 5 24 7 24 8 24 15 25 3 26 1 26 2 26 3 27 5 28 1 28 3 28 4 28 6 ...