QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#640774#7738. Equivalent RewritingyellWA 1ms3648kbC++201.3kb2024-10-14 15:56:152024-10-14 15:56:19

Judging History

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

  • [2024-10-14 15:56:19]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3648kb
  • [2024-10-14 15:56:15]
  • 提交

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

詳細信息

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)