QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#511266#5450. 比赛AdamGS#0 0ms0kbC++231.4kb2024-08-09 18:09:332024-08-09 18:09:34

Judging History

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

  • [2024-08-09 18:09:34]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-08-09 18:09:33]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=2e3+7;
vector<int>V[LIM], P[LIM*LIM], T[LIM];
int ile[LIM*LIM], odw[LIM];
void solve() {
	int n, m;
	cin >> n >> m;
	if(m==0) {
		rep(i, n) cout << i+1 << " ";
		cout << '\n';
		return;
	}
	rep(i, n) odw[i]=0;
	rep(i, n) T[i].clear();
	rep(i, n) V[i].clear();
	rep(i, m) P[i].clear();
	pair<int,int>ma={0, 0};
	rep(i, m) {
		int k;
		cin >> k;
		ile[i]=k;
		ma=max(ma, {k, i});
		rep(j, k) {
			int x;
			cin >> x; --x;
			P[i].pb(x);
			V[x].pb(i);
		}
	}
	if(ma.st*3>2*n) {
		cout << -1 << '\n';
		return;
	}
	int z=ma.st;
	if(n-z<z) z=n-ma.st;
	int akt=0;
	rep(i, z) {
		int x=P[ma.nd].back();
		P[ma.nd].pop_back();
		T[akt].pb(x);
		for(auto j : V[x]) --ile[j];
		odw[x]=1;
		akt=(akt+1)%z;
	}
	rep(i, n-z) {
		ma={0, 0};
		rep(j, m) ma=max(ma, {ile[j], j});
		while(odw[P[ma.nd].back()]) P[ma.nd].pop_back();
		int x=P[ma.nd].back();
		P[ma.nd].pop_back();
		T[akt].pb(x);
		for(auto j : V[x]) --ile[j];
		odw[x]=1;
		akt=(akt+1)%z;
	}
	rep(i, z) for(auto j : T[i]) cout << j+1 << " ";
	cout << '\n';
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int _=1;
	cin >> _;
	while(_--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

248
9 3
3 3 4 5
3 1 2 3
4 6 7 8 9
8 1
4 3 4 5 6
9 2
5 1 2 3 4 5
3 6 7 8
6 1
4 3 4 5 6
7 2
3 3 4 5
3 1 2 3
9 3
4 1 2 3 4
3 4 5 6
3 6 7 8
7 1
4 4 5 6 7
8 2
3 6 7 8
3 2 3 4
8 2
4 1 2 3 4
4 4 5 6 7
3 0
9 3
3 2 3 4
3 7 8 9
3 4 5 6
6 1
5 1 2 3 4 5
9 2
4 1 2 3 4
3 6 7 8
9 3
3 6 7 8
3 3 4 5
3 1 2 3
8 1
8 1 ...

output:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Runtime Error

Test #25:

score: 0
Runtime Error

input:

5
400 1
266 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:


result:


Subtask #5:

score: 0
Runtime Error

Test #36:

score: 0
Runtime Error

input:

5
400 1
266 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:


result:


Subtask #6:

score: 0
Skipped

Dependency #1:

0%

Subtask #7:

score: 0
Skipped

Dependency #4:

0%

Subtask #8:

score: 0
Skipped

Dependency #5:

0%

Subtask #9:

score: 0
Skipped

Dependency #1:

0%