QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#640774 | #7738. Equivalent Rewriting | yell | WA | 1ms | 3648kb | C++20 | 1.3kb | 2024-10-14 15:56:15 | 2024-10-14 15:56:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
void solve() {
int n, m;
cin >> n >> m;
vector<vector<int>> a(m + 1);
for (int i = 1; i <= n; i++) {
int sz;
cin >> sz;
for (int j = 1; j <= sz; j++) {
int x;
cin >> x;
a[x].push_back(i);
}
}
priority_queue<pair<int, int>> q;
for (int i = 1; i <= m; i++) {
q.push({(int)a[i].size(), i});
}
vector<int> ans;
vector<int> vis(n + 1);
while (!q.empty()) {
auto [siz, idx] = q.top();
q.pop();
if (siz == 0) break;
if (!vis[a[idx].back()]) {
ans.push_back(a[idx].back());
vis[a[idx].back()] = 1;
}
a[idx].pop_back();
q.push({siz - 1, idx});
}
reverse(ans.begin(), ans.end());
vector<int> b(n);
iota(b.begin(), b.end(), 1);
if (ans == b) {
cout << "No\n";
} else {
cout << "Yes\n";
for (auto x : ans) {
cout << x << " ";
}
cout << "\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3584kb
input:
3 3 6 3 3 1 5 2 5 3 2 2 6 2 3 3 1 3 2 2 3 1 1 3 2 2 1
output:
Yes 1 3 2 No No
result:
ok OK. (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3648kb
input:
1 10 5 2 2 4 4 1 3 4 2 1 2 3 2 1 4 4 5 2 4 3 3 2 5 4 3 5 4 2 3 1 3 2 5 1 4 2 3 5 1 4
output:
Yes 1 2 3 4 5 6 7 8 10 9
result:
wrong answer two transactions are not equivalent. (test case 1)