QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#90935 | #6131. Tournament | ksunhokim | WA | 2ms | 3316kb | C++17 | 1.2kb | 2023-03-26 08:29:13 | 2023-03-26 08:29:17 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
int n,k;
cin >> n >> k;
vector g(n, set<int>());
for (int i=0;i<n;i++){
for(int j=0;j<n;j++) {
if (i == j) continue;
g[i].insert(j);
}
}
vector<vector<int>> ans;
for (int i=0;i<k;i++){
ans.push_back(vector<int>(n));
vector<int> vis(n);
int cnt = 0;
for (int j=0;j<n;j++){
if (vis[j]) continue;
int u = j;
for (auto it = g[u].begin(); it != g[u].end(); ++it) {
int v = *it;
if (!vis[v]) {
vis[u] = true;
vis[v] = true;
g[u].erase(v);
g[v].erase(u);
ans.back()[v] = u;
ans.back()[u] = v;
cnt += 2;
break;
}
}
}
if (cnt != n) {
cout << "Imposible" << "\n";
return;
}
}
for (int i=0;i<k;i++) {
for (int j=0;j<n;j++) {
if (j != n-1) {
cout << ans[i][j] + 1 << " ";
} else {
cout << ans[i][j] + 1;
}
}
cout << "\n";
}
}
int main() {
int t;
cin >> t;
while (t--)
solve();
}
详细
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3316kb
input:
2 3 1 4 3
output:
Imposible 2 1 4 3 3 4 1 2 4 3 2 1
result:
wrong answer 1st lines differ - expected: 'Impossible', found: 'Imposible'