QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#441982#8174. Set ConstructionHKOI0TL 1ms3836kbC++142.0kb2024-06-15 01:17:542024-06-15 01:17:55

Judging History

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

  • [2024-06-15 01:17:55]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3836kb
  • [2024-06-15 01:17:54]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define all(a) begin(a), end(a)
using namespace std;

bool check_valid(int n, int m){
	return 2 <= n && 2 <= m && m <= n * (n + 1) / 2;
}

vector<int> f(int n, int m){
	assert(check_valid(n, m));
	if (m == 2) return {0, (1LL << n) - 1};
	if (m % 2 == 1) {
		if (check_valid(n - 2, (m - 1) / 2)) {
			vector<int> a = f(n - 2, (m - 1) / 2);
			for (auto& x : a) x = x * 4 + 1;
			int k = a.size(); for (int i = 0; i < k; i++) a.push_back(a[i] + 2);
			a.push_back(0);
			return a;
		} else if (check_valid(n - 1, m - 1)) {
			vector<int> a = f(n - 1, m - 1);
			for (auto& x : a) x = x * 2 + 1;
			a.push_back(0);
			return a;
		}
	} else {
		if (check_valid(n - 1, m / 2)) {
			vector<int> a = f(n - 1, m / 2);
			for (auto& x : a) x *= 2;
			int k = a.size();
			for (int i = 0; i < k; i++) a.push_back(a[i] + 1);
			return a;
		}
	}

	if (n == 5 && m == 15) {
		vector<int> A = f(2, 3);
		vector<int> B = f(3, 5);
		vector<int> c;
		for (auto a : A) {
			for (auto b : B) {
				c.push_back((a << 3) | b);
			}
		}
		return c;
	} else if (n == 4 && m == 9) {
		vector<int> A = f(2, 3);
		vector<int> B = f(2, 3);
		vector<int> c;
		for (auto a : A) {
			for (auto b : B) {
				c.push_back((a << 2) | b);
			}
		}
		return c;
	} else if (n == 3 && m == 5) {
		return {0, 1, 2, 3, 7};
	} else if (n == 2 && m == 3) {
		return {0, 1, 3};
	} else {
		assert(false);
	}
	return {};
}

void solve() {
	int n, m; cin >> n >> m;
	vector<int> ans = f(n, m);
	sort(all(ans));
	assert(ans.size() == m);
	assert(ans[0] == 0);
	assert(ans.back() == (1LL << n) - 1);
	for (auto x : ans) {
		cout << x << ' ';
	}
	cout << endl;
	for (int i = 0; i < ans.size(); i++) {
		for (int j = 0; j < ans.size(); j++) {
			assert(binary_search(all(ans), ans[i] & ans[j]));
			assert(binary_search(all(ans), ans[i] | ans[j]));
		}
	}
}

int32_t main(){
#ifndef LOCAL
	cin.tie(0)->sync_with_stdio(false);
#endif
	int t = 1;
	cin >> t;
	while (t--) {
		solve();
	}
}

詳細信息

Test #1:

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

input:

3
3 5
4 8
60 2

output:

0 1 2 3 7 
0 1 2 3 12 13 14 15 
0 1152921504606846975 

result:

ok AC

Test #2:

score: 0
Accepted
time: 1ms
memory: 3784kb

input:

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

output:

0 63 
0 1 63 
0 1 62 63 
0 1 3 61 63 
0 1 2 3 62 63 
0 1 3 5 7 61 63 
0 1 2 3 60 61 62 63 
0 1 3 5 7 57 59 61 63 
0 1 2 3 6 7 58 59 62 63 
0 1 3 5 7 13 15 53 55 61 63 
0 1 2 3 4 5 6 7 60 61 62 63 
0 1 3 5 7 9 11 13 15 57 59 61 63 
0 1 2 3 6 7 10 11 14 15 58 59 62 63 
0 1 3 5 7 13 15 21 23 29 31 53 5...

result:

ok AC

Test #3:

score: 0
Accepted
time: 1ms
memory: 3772kb

input:

30
7 12
7 13
7 14
7 15
7 16
7 17
7 18
7 19
7 20
7 21
7 22
7 23
7 24
7 25
7 26
7 27
7 28
8 2
8 3
8 4
8 5
8 6
8 7
8 8
8 9
8 10
8 11
8 12
8 13
8 14

output:

0 1 2 3 4 5 6 7 124 125 126 127 
0 1 3 5 7 9 11 13 15 121 123 125 127 
0 1 2 3 6 7 10 11 14 15 122 123 126 127 
0 1 3 5 7 13 15 21 23 29 31 117 119 125 127 
0 1 2 3 4 5 6 7 120 121 122 123 124 125 126 127 
0 1 3 5 7 9 11 13 15 113 115 117 119 121 123 125 127 
0 1 2 3 6 7 10 11 14 15 114 115 118 119 ...

result:

ok AC

Test #4:

score: 0
Accepted
time: 1ms
memory: 3532kb

input:

30
8 15
8 16
8 17
8 18
8 19
8 20
8 21
8 22
8 23
8 24
8 25
8 26
8 27
8 28
8 29
8 30
8 31
8 32
8 33
8 34
8 35
8 36
9 2
9 3
9 4
9 5
9 6
9 7
9 8
9 9

output:

0 1 3 5 7 13 15 21 23 29 31 245 247 253 255 
0 1 2 3 4 5 6 7 248 249 250 251 252 253 254 255 
0 1 3 5 7 9 11 13 15 241 243 245 247 249 251 253 255 
0 1 2 3 6 7 10 11 14 15 242 243 246 247 250 251 254 255 
0 1 3 5 7 13 15 21 23 29 31 229 231 237 239 245 247 253 255 
0 1 2 3 4 5 6 7 12 13 14 15 244 24...

result:

ok AC

Test #5:

score: 0
Accepted
time: 1ms
memory: 3528kb

input:

30
9 10
9 11
9 12
9 13
9 14
9 15
9 16
9 17
9 18
9 19
9 20
9 21
9 22
9 23
9 24
9 25
9 26
9 27
9 28
9 29
9 30
9 31
9 32
9 33
9 34
9 35
9 36
9 37
9 38
9 39

output:

0 1 2 3 6 7 506 507 510 511 
0 1 3 5 7 13 15 501 503 509 511 
0 1 2 3 4 5 6 7 508 509 510 511 
0 1 3 5 7 9 11 13 15 505 507 509 511 
0 1 2 3 6 7 10 11 14 15 506 507 510 511 
0 1 3 5 7 13 15 21 23 29 31 501 503 509 511 
0 1 2 3 4 5 6 7 504 505 506 507 508 509 510 511 
0 1 3 5 7 9 11 13 15 497 499 501...

result:

ok AC

Test #6:

score: 0
Accepted
time: 0ms
memory: 3836kb

input:

6
9 40
9 41
9 42
9 43
9 44
9 45

output:

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 24 25 26 27 28 29 30 31 488 489 490 491 492 493 494 495 504 505 506 507 508 509 510 511 
0 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 49 51 53 55 57 59 61 63 465 467 469 471 473 475 477 479 497 499 501 503 505 507 509 511 
0 1 2 3 6 7 10 11 14 15 18 19 22 23 26 ...

result:

ok AC

Test #7:

score: -100
Time Limit Exceeded

input:

30
60 1801
60 1802
60 1803
60 1804
60 1805
60 1806
60 1807
60 1808
60 1809
60 1810
60 1811
60 1812
60 1813
60 1814
60 1815
60 1816
60 1817
60 1818
60 1819
60 1820
60 1821
60 1822
60 1823
60 1824
60 1825
60 1826
60 1827
60 1828
60 1829
60 1830

output:

0 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 49 51 53 55 57 59 61 63 81 83 85 87 89 91 93 95 113 115 117 119 121 123 125 127 145 147 149 151 153 155 157 159 177 179 181 183 185 187 189 191 209 211 213 215 217 219 221 223 241 243 245 247 249 251 253 255 273 275 277 279 281 283 285 287 305 307 309 311...

result: