QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#767370#7738. Equivalent RewritingguangxuautumnRE 3ms7712kbC++141.4kb2024-11-20 20:44:012024-11-20 20:44:01

Judging History

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

  • [2024-11-20 20:44:01]
  • 评测
  • 测评结果:RE
  • 用时:3ms
  • 内存:7712kb
  • [2024-11-20 20:44:01]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int M = 1e5 + 10;

vector<set<int>> p(M);

void solve()
{
	int n, m;

	cin >> n >> m;

	for(auto pp:p) pp.clear();

	for(int i = 0; i < n; i ++) {
		int tp;
		cin >> tp;
		for(int j = 0; j < tp; j ++) {
			int t;
			cin >> t;

			p[i].insert(t);
		}
	}
/*
	for(int i = 0; i < n; i ++) {
		for(auto pp:p[i]) cout << pp <<' ';
			cout << endl;
	}
*/	
	set<int> s;

	for(int i = n - 1; i >= 1; i --) {
		//与后方比,如果在后方出现则抹去;
		for(auto pp:p[i]) {
			if(s.find(pp) != s.end()) p[i].erase(pp);
		}
		//cout << i << ' ' << p[i].size() << endl;
		//与i-1比,若没有交集则可换
		bool flag = 0;
		for(auto pp:p[i]) {
			//find == s.end 意味着没找到
			if(p[i-1].find(pp) != p[i-1].end()) {
				//for(auto ip:p[i-1]) cout << ip << ' ';
				//	cout << endl;
				//cout << "test" << pp << endl;
				flag = 1;
				break;
			}
		}
		if(!flag) {
			//输出正解
			cout << "Yes\n";
			for(int j = 0; j < n; j ++) {
				if(j == i - 1) cout << i + 1 << ' ';
				else if(j == i) cout << i - 1 + 1 << ' ';
				else cout << j + 1 << ' ';
			}
			cout << '\n';
			return;
		}
		//插入后方大set
		for(auto pp:p[i]) s.insert(pp);
	}

	cout << "No\n";
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	cin >> t;


	while(t--)
		solve();
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 7712kb

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
Runtime Error

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:


result: