QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#304643#8004. Bit Componentucup-team1055#AC ✓7ms5368kbC++205.0kb2024-01-13 22:32:422024-01-13 22:32:43

Judging History

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

  • [2024-01-13 22:32:43]
  • 评测
  • 测评结果:AC
  • 用时:7ms
  • 内存:5368kb
  • [2024-01-13 22:32:42]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

struct UnionFind{
	int n;
	vector<int> par;

	explicit UnionFind(int v): n(v), par(v,-1) {}

	void merge(int a, int b){
		int x = find(a);
		int y = find(b);
		if (x == y) return;
		if (-par[x] < -par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return;
	}

	int find(int x){
		if (par[x] < 0) return x;
		return par[x] = find(par[x]);
	}
};

const int mx = 20;

bool assertion(vector<int> p){
	int n = p.size();
	UnionFind uf(mx * n);
	vector<vector<int>> a(n, vector<int>(mx, 0));
	rep(i,0,n){
		rep(j,0,mx){
			if(p[i] >> j & 1){
				a[i][j] = 1;
			}
			//cout << a[i][j];
		}
		//cout << '\n';
	}
	rep(i,0,n){
		rep(j,0,mx-1){
			if (a[i][j] == 1 && a[i][j+1] == 1){
				uf.merge(i * mx + j, i * mx + j + 1);
			}
		}
	}
	rep(i,0,n-1){
		rep(j,0,mx){
			if (a[i][j] == 1 && a[i+1][j] == 1){
				uf.merge(i * mx + j, i * mx + j + mx);
			}
		}
	}
	int memo = -1;
	rep(i,0,n){
		rep(j,0,mx){
			if (a[i][j] == 0) continue;
			if (memo == -1){
				memo = uf.find(i * mx + j);
			}
			if (memo != uf.find(i * mx + j)){
				return false;
			}
		}
	}
	return true;
};

void naive(int n){
	vector<int> p(n);
	iota(p.begin(), p.end(), 1);
	do{
		if(assertion(p)){
			cout << n << ' ' << "YES\n";
			rep(i,0,n){
				cout << p[i];
				if (i == n-1) cout << '\n';
				else cout << ' ';
			}
			return;
		}
	}while(next_permutation(p.begin(), p.end()));
	cout << n << ' ' << "NO\n";
	return;
}

bool seen[20];
vector<int> kekka[20];

vector<int> construct_inner(int k);
vector<int> construct(int k, int n);

vector<int> construct_inner(int k){
	if (k == 1){
		return {1};
	}	
	if (k == 2){
		return {1, 3, 2};
	}
	if (k == 3){
		return {1, 3, 2, 6, 4, 5, 7};
	}
	if (seen[k]) return kekka[k];
	vector<int> ret = construct(k, (1 << k) - 1);
	seen[k] = 1;
	kekka[k] = ret;
	return ret;
}

vector<int> construct(int k, int n){
	vector<int> now = construct_inner(k-1);
	vector<int> tar = construct_inner(k-2);
	if (k >= 5 && n == (1 << k) - 1){
		rep(i,0, 1){
			if ((1 << k-1) + (1 << k-2) + tar[i] <= n){
				now.push_back(tar[i] + (1 << k-1) + (1 << k-2));
			}
			if ((1 << k-1) + tar[i] <= n){
				now.push_back(tar[i] + (1 << k-1));
			}
		}
		if ((1 << k-1) + (1 << k-2) + 0 <= n){
			now.push_back((1 << k-1) + (1 << k-2));
		}
		if ((1 << k-1) <= n){
			now.push_back((1 << k-1));
		}
		rep(i,1,(1 << k-2) - 1){
			if ((1 << k-1) + tar[i] <= n){
				now.push_back(tar[i] + (1 << k-1));
			}
			if ((1 << k-1) + (1 << k-2) + tar[i] <= n){
				now.push_back(tar[i] + (1 << k-1) + (1 << k-2));
			}
		}
		return now;
	}else if ( k >= 5){
		rep(i,0,(1 << k-2) -1){
			if ((1 << k-1) + (1 << k-2) + tar[i] <= n){
				now.push_back(tar[i] + (1 << k-1) + (1 << k-2));
			}
			if ((1 << k-1) + tar[i] <= n){
				now.push_back(tar[i] + (1 << k-1));
			}
		}
		if ((1 << k-1) + (1 << k-2) + 0 <= n){
			now.push_back((1 << k-1) + (1 << k-2));
		}
		if ((1 << k-1) <= n){
			now.push_back((1 << k-1));
		}
		return now;
	}else{
		rep(i,0, (1 << k-2) - 1){
			if ((1 << k-1) + (1 << k-2) + tar[i] <= n && (1 << k-1) + (1 << k-2) + tar[i] != (1 << k) - 1){
				now.push_back(tar[i] + (1 << k-1) + (1 << k-2));
			}
			if ((1 << k-1) + tar[i] <= n){
				now.push_back(tar[i] + (1 << k-1));
			}
		}
		if ((1 << k-1) + (1 << k-2) <= n){
			now.push_back((1 << k-1) + (1 << k-2));
		}
		if ((1 << k-1) <= n){
			now.push_back((1 << k-1));
		}
		if ((1 << k) - 1 <= n){
			now.push_back((1 << k) - 1);
		}
		return now;
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n; cin >> n;

	int k = 0;
	while ((1 << k) <= n){
		k++;
	}
	if (n == 1){
		cout << "YES\n";
		cout << "1\n";
		return 0;
	}
	if (n == 2){
		cout << "NO\n";
		return 0;
	}
	if (n == 3){
		cout << "YES\n";
		cout << "2 3 1\n";
		return 0;
	}
	if (n == 7){
		cout << "YES\n";
		cout << "1 3 2 6 4 5 7\n";
		return 0;
	}
	if (n < (1 << k-2) + (1 << k-1) + 1){
		cout << "NO\n";
	}else{
		cout << "YES\n";
		vector<int> ans = construct(k, n);
		rep(i,0,n){
			cout << ans[i];
			if (i == n-1) cout << '\n';
			else cout << ' ';
		}
		//assert(assertion(ans));
	}
}


这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3520kb

input:

1

output:

YES
1

result:

ok answer is 1

Test #2:

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

input:

2

output:

NO

result:

ok answer is 0

Test #3:

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

input:

3

output:

YES
2 3 1

result:

ok answer is 1

Test #4:

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

input:

4

output:

NO

result:

ok answer is 0

Test #5:

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

input:

5

output:

NO

result:

ok answer is 0

Test #6:

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

input:

6

output:

NO

result:

ok answer is 0

Test #7:

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

input:

7

output:

YES
1 3 2 6 4 5 7

result:

ok answer is 1

Test #8:

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

input:

8

output:

NO

result:

ok answer is 0

Test #9:

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

input:

9

output:

NO

result:

ok answer is 0

Test #10:

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

input:

10

output:

NO

result:

ok answer is 0

Test #11:

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

input:

11

output:

NO

result:

ok answer is 0

Test #12:

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

input:

12

output:

NO

result:

ok answer is 0

Test #13:

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

input:

13

output:

YES
1 3 2 6 4 5 7 13 9 11 10 12 8

result:

ok answer is 1

Test #14:

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

input:

14

output:

YES
1 3 2 6 4 5 7 13 9 11 14 10 12 8

result:

ok answer is 1

Test #15:

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

input:

15

output:

YES
1 3 2 6 4 5 7 13 9 11 14 10 12 8 15

result:

ok answer is 1

Test #16:

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

input:

16

output:

NO

result:

ok answer is 0

Test #17:

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

input:

17

output:

NO

result:

ok answer is 0

Test #18:

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

input:

23

output:

NO

result:

ok answer is 0

Test #19:

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

input:

24

output:

NO

result:

ok answer is 0

Test #20:

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

input:

25

output:

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

result:

ok answer is 1

Test #21:

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

input:

26

output:

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

result:

ok answer is 1

Test #22:

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

input:

27

output:

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

result:

ok answer is 1

Test #23:

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

input:

40

output:

NO

result:

ok answer is 0

Test #24:

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

input:

53

output:

YES
1 3 2 6 4 5 7 13 9 11 14 10 12 8 15 25 17 24 16 19 27 18 26 22 30 20 28 21 29 23 31 49 33 51 35 50 34 38 52 36 53 37 39 45 41 43 46 42 44 40 47 48 32

result:

ok answer is 1

Test #25:

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

input:

93

output:

NO

result:

ok answer is 0

Test #26:

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

input:

105

output:

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

result:

ok answer is 1

Test #27:

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

input:

132

output:

NO

result:

ok answer is 0

Test #28:

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

input:

221

output:

YES
1 3 2 6 4 5 7 13 9 11 14 10 12 8 15 25 17 24 16 19 27 18 26 22 30 20 28 21 29 23 31 49 33 48 32 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 46 62 42 58 44 60 40 56 47 63 97 65 96 64 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 78 110 74 106 76 108 72 104 79 111 89 121 8...

result:

ok answer is 1

Test #29:

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

input:

373

output:

NO

result:

ok answer is 0

Test #30:

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

input:

473

output:

YES
1 3 2 6 4 5 7 13 9 11 14 10 12 8 15 25 17 24 16 19 27 18 26 22 30 20 28 21 29 23 31 49 33 48 32 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 46 62 42 58 44 60 40 56 47 63 97 65 96 64 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 78 110 74 106 76 108 72 104 79 111 89 121 8...

result:

ok answer is 1

Test #31:

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

input:

513

output:

NO

result:

ok answer is 0

Test #32:

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

input:

934

output:

YES
1 3 2 6 4 5 7 13 9 11 14 10 12 8 15 25 17 24 16 19 27 18 26 22 30 20 28 21 29 23 31 49 33 48 32 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 46 62 42 58 44 60 40 56 47 63 97 65 96 64 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 78 110 74 106 76 108 72 104 79 111 89 121 8...

result:

ok answer is 1

Test #33:

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

input:

1356

output:

NO

result:

ok answer is 0

Test #34:

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

input:

1651

output:

YES
1 3 2 6 4 5 7 13 9 11 14 10 12 8 15 25 17 24 16 19 27 18 26 22 30 20 28 21 29 23 31 49 33 48 32 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 46 62 42 58 44 60 40 56 47 63 97 65 96 64 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 78 110 74 106 76 108 72 104 79 111 89 121 8...

result:

ok answer is 1

Test #35:

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

input:

2263

output:

NO

result:

ok answer is 0

Test #36:

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

input:

3330

output:

YES
1 3 2 6 4 5 7 13 9 11 14 10 12 8 15 25 17 24 16 19 27 18 26 22 30 20 28 21 29 23 31 49 33 48 32 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 46 62 42 58 44 60 40 56 47 63 97 65 96 64 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 78 110 74 106 76 108 72 104 79 111 89 121 8...

result:

ok answer is 1

Test #37:

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

input:

4375

output:

NO

result:

ok answer is 0

Test #38:

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

input:

7989

output:

YES
1 3 2 6 4 5 7 13 9 11 14 10 12 8 15 25 17 24 16 19 27 18 26 22 30 20 28 21 29 23 31 49 33 48 32 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 46 62 42 58 44 60 40 56 47 63 97 65 96 64 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 78 110 74 106 76 108 72 104 79 111 89 121 8...

result:

ok answer is 1

Test #39:

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

input:

10925

output:

NO

result:

ok answer is 0

Test #40:

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

input:

14097

output:

YES
1 3 2 6 4 5 7 13 9 11 14 10 12 8 15 25 17 24 16 19 27 18 26 22 30 20 28 21 29 23 31 49 33 48 32 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 46 62 42 58 44 60 40 56 47 63 97 65 96 64 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 78 110 74 106 76 108 72 104 79 111 89 121 8...

result:

ok answer is 1

Test #41:

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

input:

16893

output:

NO

result:

ok answer is 0

Test #42:

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

input:

28913

output:

YES
1 3 2 6 4 5 7 13 9 11 14 10 12 8 15 25 17 24 16 19 27 18 26 22 30 20 28 21 29 23 31 49 33 48 32 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 46 62 42 58 44 60 40 56 47 63 97 65 96 64 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 78 110 74 106 76 108 72 104 79 111 89 121 8...

result:

ok answer is 1

Test #43:

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

input:

40092

output:

NO

result:

ok answer is 0

Test #44:

score: 0
Accepted
time: 3ms
memory: 3892kb

input:

54980

output:

YES
1 3 2 6 4 5 7 13 9 11 14 10 12 8 15 25 17 24 16 19 27 18 26 22 30 20 28 21 29 23 31 49 33 48 32 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 46 62 42 58 44 60 40 56 47 63 97 65 96 64 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 78 110 74 106 76 108 72 104 79 111 89 121 8...

result:

ok answer is 1

Test #45:

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

input:

88104

output:

NO

result:

ok answer is 0

Test #46:

score: 0
Accepted
time: 6ms
memory: 4540kb

input:

106284

output:

YES
1 3 2 6 4 5 7 13 9 11 14 10 12 8 15 25 17 24 16 19 27 18 26 22 30 20 28 21 29 23 31 49 33 48 32 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 46 62 42 58 44 60 40 56 47 63 97 65 96 64 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 78 110 74 106 76 108 72 104 79 111 89 121 8...

result:

ok answer is 1

Test #47:

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

input:

152797

output:

NO

result:

ok answer is 0

Test #48:

score: 0
Accepted
time: 7ms
memory: 5368kb

input:

200000

output:

YES
1 3 2 6 4 5 7 13 9 11 14 10 12 8 15 25 17 24 16 19 27 18 26 22 30 20 28 21 29 23 31 49 33 48 32 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 46 62 42 58 44 60 40 56 47 63 97 65 96 64 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 78 110 74 106 76 108 72 104 79 111 89 121 8...

result:

ok answer is 1

Test #49:

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

input:

3073

output:

YES
1 3 2 6 4 5 7 13 9 11 14 10 12 8 15 25 17 24 16 19 27 18 26 22 30 20 28 21 29 23 31 49 33 48 32 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 46 62 42 58 44 60 40 56 47 63 97 65 96 64 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 78 110 74 106 76 108 72 104 79 111 89 121 8...

result:

ok answer is 1

Test #50:

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

input:

16383

output:

YES
1 3 2 6 4 5 7 13 9 11 14 10 12 8 15 25 17 24 16 19 27 18 26 22 30 20 28 21 29 23 31 49 33 48 32 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 46 62 42 58 44 60 40 56 47 63 97 65 96 64 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 78 110 74 106 76 108 72 104 79 111 89 121 8...

result:

ok answer is 1

Test #51:

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

input:

32767

output:

YES
1 3 2 6 4 5 7 13 9 11 14 10 12 8 15 25 17 24 16 19 27 18 26 22 30 20 28 21 29 23 31 49 33 48 32 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 46 62 42 58 44 60 40 56 47 63 97 65 96 64 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 78 110 74 106 76 108 72 104 79 111 89 121 8...

result:

ok answer is 1

Test #52:

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

input:

399

output:

YES
1 3 2 6 4 5 7 13 9 11 14 10 12 8 15 25 17 24 16 19 27 18 26 22 30 20 28 21 29 23 31 49 33 48 32 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 46 62 42 58 44 60 40 56 47 63 97 65 96 64 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 78 110 74 106 76 108 72 104 79 111 89 121 8...

result:

ok answer is 1

Test #53:

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

input:

5757

output:

NO

result:

ok answer is 0

Test #54:

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

input:

179

output:

NO

result:

ok answer is 0

Test #55:

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

input:

228

output:

YES
1 3 2 6 4 5 7 13 9 11 14 10 12 8 15 25 17 24 16 19 27 18 26 22 30 20 28 21 29 23 31 49 33 48 32 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 46 62 42 58 44 60 40 56 47 63 97 65 96 64 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 78 110 74 106 76 108 72 104 79 111 89 121 8...

result:

ok answer is 1

Extra Test:

score: 0
Extra Test Passed