QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#271750#7738. Equivalent Rewritingucup-team1196#WA 1ms3432kbC++231.7kb2023-12-02 14:24:092023-12-02 14:24:09

Judging History

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

  • [2023-12-02 14:24:09]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3432kb
  • [2023-12-02 14:24:09]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

using ll = long long;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> q(n + 1);
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        q[i].push_back(x);
        for (int j = 1; j <= q[i][0]; j++) {
            cin >> x;
            q[i].push_back(x);
        }
    }
    vector<int> is(m + 1, 0);
    for (int i = n; i >= 2; i--) {
        map<int, int> a, b;
        for (int j = 1; j <= q[i - 1][0]; j++) {
            if (!is[q[i - 1][j]]) a[q[i - 1][j]] = j;
        }
        for (int j = 1; j <= q[i][0]; j++) {
            if (!is[q[i][j]]) a[q[i][j]] = j;
        }
        for (int j = 1; j <= q[i][0]; j++) {
            if (!is[q[i][j]]) b[q[i][j]] = j;
        }
        for (int j = 1; j <= q[i - 1][0]; j++) {
            if (!is[q[i - 1][j]])  b[q[i - 1][j]] = j;
        }
        for (auto [x, y] : a) {
            if (b[x] != y && b[x] != 0) goto G;
        }
        if (1) {
            cout << "Yes \n";
            for (int j = 1; j <= n; j++) {
                if (j == i) {
                    cout << i - 1 << " ";
                } else if (j == i - 1) {
                    cout << i << " ";
                } else {
                    cout << j << " ";
                }
            }
            cout << "\n";
            return;
        }
        G:;
        for (int j = 1; j <= q[i][0]; j++) {
            is[q[i][j]] = 1;
        }
    }
    cout << "No \n";

}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3428kb

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: 0
Accepted
time: 1ms
memory: 3432kb

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 8 7 9 10 

result:

ok OK. (1 test case)

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3420kb

input:

1
20 5
5 4 1 2 5 3
2 5 3
3 5 1 2
5 4 5 1 3 2
3 4 2 5
5 3 1 5 4 2
5 5 1 2 3 4
1 3
4 5 1 2 3
4 4 1 3 5
2 5 2
4 2 3 5 1
3 2 4 5
5 2 3 4 1 5
4 5 2 4 3
1 2
2 4 3
4 4 5 3 1
5 4 1 5 3 2
3 5 1 3

output:

Yes 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 19 18 20 

result:

wrong answer two transactions are not equivalent. (test case 1)