QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#251351#7738. Equivalent Rewritingremain11WA 1ms7636kbC++111.8kb2023-11-14 16:19:262023-11-14 16:19:26

Judging History

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

  • [2023-11-14 16:19:26]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7636kb
  • [2023-11-14 16:19:26]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
#include<string>
#include<queue>
#include<map>
#include<unordered_map>
#include<algorithm>
#include<bitset>
using namespace std;
//#define int long long
#define x first
#define y second
const int N = 1e5 + 10;
int n, m,p[N],st[N],p1[N],p2[N];
vector<int> v[N];

void solve()
{
    scanf("%d%d", &n, &m); 
    int tmp, move;
    for (int i = 1; i <= n; i++)
    {
        v[i].clear(); 
        scanf("%d", &tmp);
        while (tmp--)
        {
            scanf("%d", &move);
            v[i].push_back(move);
        }
    }
    memset(st, -1, sizeof st);
    for (int i = n; i >= 2; i--)
    {
        memcpy(p2, st, sizeof st);
        for (int j = 0; j < v[i].size(); j++)
        {
           if(st[v[i][j]]==-1) st[v[i][j]] = i;
           if(p1[v[i][j]]==-1) p1[v[i][j]] = i;
        }
        for (int j = 0; j < v[i - 1].size(); j++)
        {
           if(p1[v[i-1][j]]==-1) p1[v[i - 1][j]] = i - 1;
           if(p2[v[i-1][j]]==-1) p2[v[i - 1][j]] = i - 1;
        }
        for (int j = 0; j < v[i].size(); j++)
        {
           if(p2[v[i][j]]==-1) p2[v[i][j]] = i;
        }
        bool flag = true;
        for (int i = 1; i <= m; i++)
        {
            if (p1[i]!= p2[i]) flag = false;
        }

        if (flag)
        {
            swap(p[i], p[i - 1]);
            printf("Yes\n");
            for (int i = 1; i <= n; i++)
            {
                printf("%d ", p[i]);
            }
            printf("\n");
            swap(p[i], p[i - 1]);
            return;
        }
    } 
    printf("No\n");
}

signed main()
{
    int T;
    scanf("%d", &T);
    for (int i = 1; i < N; i++) p[i] = i;
    while (T--)
    {
        solve();
    }

    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7636kb

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:

No
No
No

result:

wrong answer jury found an answer but participant did not (test case 1)