QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#617674#7738. Equivalent RewritingasaltfishWA 1ms9760kbC++232.9kb2024-10-06 16:36:302024-10-06 16:36:31

Judging History

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

  • [2024-10-06 16:36:31]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9760kb
  • [2024-10-06 16:36:30]
  • 提交

answer

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string.h>
#include<iomanip>
#include<stack>
#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define ll               long long
#define endl             "\n"
using namespace std;
inline int read() { register int s = 0, w = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-')w = -1; ch = getchar(); }while (ch >= '0' && ch <= '9')s = s * 10 + ch - '0', ch = getchar(); return s * w; }
ll t, q, n, a[200005], b[200005], p, num[200005], c[200005], d[200005];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> t;
    while (t--)
    {
        cin >> q >> n;
        for (int i = 1; i <= q; i++)
        {
            cin >> num[i];
            for (int j = 1; j <= num[i]; j++)
            {
                cin >> p;
                b[p] = a[p];
                a[p] = i;
            }
        }
        if (q == 1)
        {
            cout << "No";
            if (t)cout << endl;
            continue;
        }
        for (int i = 1; i <= n; i++)
        {
            c[a[i]]++;
            d[a[i]] = max(b[i], d[a[i]]);
        }
        bool flag = 0;
        for (int i = 1; i <= q; i++)
        {
            if (c[i] == 0 && i > 1)
            {
                flag = 1;
                ll sum = 1;
                cout << "Yes" << endl << i << " ";
                for (int j = 1; j <= q; j++)
                {
                    if (j != i)cout << j;
                    sum++;
                    if (sum != n)cout << " ";
                }
                break;
            }
            else if (c[i] == num[i])
            {
                ll sum = 0;
                if (i - 1 > d[i])
                {
                    flag = 1;
                    cout << "Yes" << endl;
                    for (int j = 1; j <= q; j++)
                    {
                        if (j == i - 1)cout << i;
                        else if (j == i)cout << i - 1;
                        else cout << j;
                        if (j != n)cout << " ";
                    }
                    break;
                }
                else if (i < q)
                {
                    flag = 1;
                    cout << "Yes" << endl;
                    for (int j = 1; j <= q; j++)
                    {
                        if (j == i)cout << q;
                        else if (j == q)cout << i;
                        else cout << j;
                        if (j != n)cout << " ";
                    }
                    break;
                }
            }
        }
        if (!flag)cout << "No";
        if (t)cout << endl;
        for (int i = 1; i <= max(n,q); i++)
        {
            a[i] = b[i] = c[i] = d[i] = num[i] = 0;
        }
    }
    return 0;
}

詳細信息

Test #1:

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

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: 1ms
memory: 9760kb

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
2 1  3 45 6 7 8 9 10 

result:

wrong answer Integer parameter [name=q_i] equals to 45, violates the range [1, 10] (test case 1)