QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#90935#6131. TournamentksunhokimWA 2ms3316kbC++171.2kb2023-03-26 08:29:132023-03-26 08:29:17

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-26 08:29:17]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3316kb
  • [2023-03-26 08:29:13]
  • 提交

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();
}

Details

Tip: Click on the bar to expand more detailed information

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'