QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#304149 | #8004. Bit Component | ucup-team087# | AC ✓ | 14ms | 5732kb | C++14 | 4.2kb | 2024-01-13 15:15:30 | 2024-01-13 15:15:30 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
vector<int> uf;
int root(int u) {
return (uf[u] < 0) ? u : (uf[u] = root(uf[u]));
}
bool connect(int u, int v) {
u = root(u);
v = root(v);
if (u == v) return false;
if (uf[u] > uf[v]) swap(u, v);
uf[u] += uf[v];
uf[v] = u;
return true;
}
constexpr int E = 22;
int N;
vector<int> us;
bool check() {
uf.assign(N * E, -1);
for (int x = 0; x < N; ++x) for (int y = 0; y < E; ++y) if (us[x] >> (y) & 1) {
if (x + 1 < N && (us[x + 1] >> (y) & 1)) connect(x * E + y, (x + 1) * E + y);
if (y + 1 < N && (us[x] >> (y + 1) & 1)) connect(x * E + y, x * E + (y + 1));
}
int numComps = 0;
for (int x = 0; x < N; ++x) for (int y = 0; y < E; ++y) if (us[x] >> (y) & 1) {
if (uf[x * E + y] < 0) ++numComps;
}
return (numComps == 1);
}
bool dfs(int i, Int used) {
if (i == N) {
if (check()) {
return true;
}
} else {
for (int &u = us[i] = 1; u <= N; ++u) if (!(used >> u & 1)) {
if (i == 0 || (us[i - 1] & u)) {
if (dfs(i + 1, used | 1LL << u)) {
return true;
}
}
}
}
return false;
}
void exper() {
for (N = 1; ; ++N) {
us.resize(N);
const bool res = dfs(0, 0);
if (res) {
cerr << N << ": " << us << endl;
for (int i = 0; i < N; ++i) {
for (int e = E; --e >= 0; ) {
cerr << (us[i] >> e & 1);
}
cerr << endl;
}
} else {
cerr << N << ": NO" << endl;
}
}
}
#define N do_not_use_N
vector<int> solve(int n) {
if (n == 1) return {1};
if (n == 3) return {1, 3, 2};
if (n == 7) return {1, 3, 2, 6, 4, 5, 7};
if (n <= 7) return {};
const int t = 31 - __builtin_clz(n);
const int n0 = (1<<t) + (1<<(t-1)) + 1;
const int last = (1<<(t+1)) - 1;
if (n < n0) return {};
const auto as = solve((1<<t) - 1);
const auto as1 = solve((1<<(t-1)) - 1);
auto ret = as;
ret.push_back(n0);
for (const int a : as1) {
ret.push_back((1<<t) + a);
const int b = (1<<t) + (1<<(t-1)) + a;
if (n0 < b && b <= n && b < last) {
ret.push_back(b);
}
}
ret.push_back((1<<t));
ret.push_back((1<<t) + (1<<(t-1)));
if (last <= n) {
ret.push_back(last);
}
return ret;
}
#undef N
void stress() {
// for (N = 1; N <= 100; ++N) {
for (N = 200'000; N <= 200'000; ++N) {
us = solve(N);
cerr << N << ": " << us << endl;
if (us.size()) {
for (int i = 0; i < N; ++i) {
assert(1 <= us[i]); assert(us[i] <= N);
}
assert((int)set<int>(us.begin(), us.end()).size() == N);
assert(check());
}
}
}
int main() {
// exper();
#ifdef LOCAL
stress();
#endif
for (; ~scanf("%d", &N); ) {
us = solve(N);
if (us.size()) {
puts("YES");
for (int i = 0; i < N; ++i) {
if (i) printf(" ");
printf("%d", us[i]);
}
puts("");
} else {
puts("NO");
}
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3748kb
input:
1
output:
YES 1
result:
ok answer is 1
Test #2:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
2
output:
NO
result:
ok answer is 0
Test #3:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
3
output:
YES 1 3 2
result:
ok answer is 1
Test #4:
score: 0
Accepted
time: 0ms
memory: 3912kb
input:
4
output:
NO
result:
ok answer is 0
Test #5:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
5
output:
NO
result:
ok answer is 0
Test #6:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
6
output:
NO
result:
ok answer is 0
Test #7:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
7
output:
YES 1 3 2 6 4 5 7
result:
ok answer is 1
Test #8:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
8
output:
NO
result:
ok answer is 0
Test #9:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
9
output:
NO
result:
ok answer is 0
Test #10:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
10
output:
NO
result:
ok answer is 0
Test #11:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
11
output:
NO
result:
ok answer is 0
Test #12:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
12
output:
NO
result:
ok answer is 0
Test #13:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
13
output:
YES 1 3 2 6 4 5 7 13 9 11 10 8 12
result:
ok answer is 1
Test #14:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
14
output:
YES 1 3 2 6 4 5 7 13 9 11 10 14 8 12
result:
ok answer is 1
Test #15:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
15
output:
YES 1 3 2 6 4 5 7 13 9 11 10 14 8 12 15
result:
ok answer is 1
Test #16:
score: 0
Accepted
time: 0ms
memory: 3700kb
input:
16
output:
NO
result:
ok answer is 0
Test #17:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
17
output:
NO
result:
ok answer is 0
Test #18:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
23
output:
NO
result:
ok answer is 0
Test #19:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
24
output:
NO
result:
ok answer is 0
Test #20:
score: 0
Accepted
time: 0ms
memory: 4020kb
input:
25
output:
YES 1 3 2 6 4 5 7 13 9 11 10 14 8 12 15 25 17 19 18 22 20 21 23 16 24
result:
ok answer is 1
Test #21:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
26
output:
YES 1 3 2 6 4 5 7 13 9 11 10 14 8 12 15 25 17 19 18 26 22 20 21 23 16 24
result:
ok answer is 1
Test #22:
score: 0
Accepted
time: 0ms
memory: 4008kb
input:
27
output:
YES 1 3 2 6 4 5 7 13 9 11 10 14 8 12 15 25 17 19 27 18 26 22 20 21 23 16 24
result:
ok answer is 1
Test #23:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
40
output:
NO
result:
ok answer is 0
Test #24:
score: 0
Accepted
time: 0ms
memory: 4044kb
input:
53
output:
YES 1 3 2 6 4 5 7 13 9 11 10 14 8 12 15 25 17 19 27 18 26 22 30 20 28 21 29 23 16 24 31 49 33 35 51 34 50 38 36 52 37 53 39 45 41 43 42 46 40 44 47 32 48
result:
ok answer is 1
Test #25:
score: 0
Accepted
time: 0ms
memory: 3924kb
input:
93
output:
NO
result:
ok answer is 0
Test #26:
score: 0
Accepted
time: 0ms
memory: 4048kb
input:
105
output:
YES 1 3 2 6 4 5 7 13 9 11 10 14 8 12 15 25 17 19 27 18 26 22 30 20 28 21 29 23 16 24 31 49 33 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 42 58 46 62 40 56 44 60 47 32 48 63 97 65 67 99 66 98 70 102 68 100 69 101 71 103 77 73 105 75 74 78 72 104 76 79 89 81 83 91 82 90 86 94 84 92 85 93 87...
result:
ok answer is 1
Test #27:
score: 0
Accepted
time: 0ms
memory: 3660kb
input:
132
output:
NO
result:
ok answer is 0
Test #28:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
221
output:
YES 1 3 2 6 4 5 7 13 9 11 10 14 8 12 15 25 17 19 27 18 26 22 30 20 28 21 29 23 16 24 31 49 33 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 42 58 46 62 40 56 44 60 47 32 48 63 97 65 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 74 106 78 110 72 104 76 108 79 111 89 121 81 113 ...
result:
ok answer is 1
Test #29:
score: 0
Accepted
time: 0ms
memory: 3908kb
input:
373
output:
NO
result:
ok answer is 0
Test #30:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
473
output:
YES 1 3 2 6 4 5 7 13 9 11 10 14 8 12 15 25 17 19 27 18 26 22 30 20 28 21 29 23 16 24 31 49 33 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 42 58 46 62 40 56 44 60 47 32 48 63 97 65 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 74 106 78 110 72 104 76 108 79 111 89 121 81 113 ...
result:
ok answer is 1
Test #31:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
513
output:
NO
result:
ok answer is 0
Test #32:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
934
output:
YES 1 3 2 6 4 5 7 13 9 11 10 14 8 12 15 25 17 19 27 18 26 22 30 20 28 21 29 23 16 24 31 49 33 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 42 58 46 62 40 56 44 60 47 32 48 63 97 65 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 74 106 78 110 72 104 76 108 79 111 89 121 81 113 ...
result:
ok answer is 1
Test #33:
score: 0
Accepted
time: 0ms
memory: 3660kb
input:
1356
output:
NO
result:
ok answer is 0
Test #34:
score: 0
Accepted
time: 1ms
memory: 3788kb
input:
1651
output:
YES 1 3 2 6 4 5 7 13 9 11 10 14 8 12 15 25 17 19 27 18 26 22 30 20 28 21 29 23 16 24 31 49 33 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 42 58 46 62 40 56 44 60 47 32 48 63 97 65 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 74 106 78 110 72 104 76 108 79 111 89 121 81 113 ...
result:
ok answer is 1
Test #35:
score: 0
Accepted
time: 0ms
memory: 3700kb
input:
2263
output:
NO
result:
ok answer is 0
Test #36:
score: 0
Accepted
time: 1ms
memory: 3780kb
input:
3330
output:
YES 1 3 2 6 4 5 7 13 9 11 10 14 8 12 15 25 17 19 27 18 26 22 30 20 28 21 29 23 16 24 31 49 33 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 42 58 46 62 40 56 44 60 47 32 48 63 97 65 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 74 106 78 110 72 104 76 108 79 111 89 121 81 113 ...
result:
ok answer is 1
Test #37:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
4375
output:
NO
result:
ok answer is 0
Test #38:
score: 0
Accepted
time: 1ms
memory: 3944kb
input:
7989
output:
YES 1 3 2 6 4 5 7 13 9 11 10 14 8 12 15 25 17 19 27 18 26 22 30 20 28 21 29 23 16 24 31 49 33 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 42 58 46 62 40 56 44 60 47 32 48 63 97 65 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 74 106 78 110 72 104 76 108 79 111 89 121 81 113 ...
result:
ok answer is 1
Test #39:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
10925
output:
NO
result:
ok answer is 0
Test #40:
score: 0
Accepted
time: 1ms
memory: 3928kb
input:
14097
output:
YES 1 3 2 6 4 5 7 13 9 11 10 14 8 12 15 25 17 19 27 18 26 22 30 20 28 21 29 23 16 24 31 49 33 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 42 58 46 62 40 56 44 60 47 32 48 63 97 65 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 74 106 78 110 72 104 76 108 79 111 89 121 81 113 ...
result:
ok answer is 1
Test #41:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
16893
output:
NO
result:
ok answer is 0
Test #42:
score: 0
Accepted
time: 2ms
memory: 3924kb
input:
28913
output:
YES 1 3 2 6 4 5 7 13 9 11 10 14 8 12 15 25 17 19 27 18 26 22 30 20 28 21 29 23 16 24 31 49 33 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 42 58 46 62 40 56 44 60 47 32 48 63 97 65 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 74 106 78 110 72 104 76 108 79 111 89 121 81 113 ...
result:
ok answer is 1
Test #43:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
40092
output:
NO
result:
ok answer is 0
Test #44:
score: 0
Accepted
time: 0ms
memory: 3856kb
input:
54980
output:
YES 1 3 2 6 4 5 7 13 9 11 10 14 8 12 15 25 17 19 27 18 26 22 30 20 28 21 29 23 16 24 31 49 33 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 42 58 46 62 40 56 44 60 47 32 48 63 97 65 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 74 106 78 110 72 104 76 108 79 111 89 121 81 113 ...
result:
ok answer is 1
Test #45:
score: 0
Accepted
time: 0ms
memory: 3692kb
input:
88104
output:
NO
result:
ok answer is 0
Test #46:
score: 0
Accepted
time: 3ms
memory: 4372kb
input:
106284
output:
YES 1 3 2 6 4 5 7 13 9 11 10 14 8 12 15 25 17 19 27 18 26 22 30 20 28 21 29 23 16 24 31 49 33 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 42 58 46 62 40 56 44 60 47 32 48 63 97 65 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 74 106 78 110 72 104 76 108 79 111 89 121 81 113 ...
result:
ok answer is 1
Test #47:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
152797
output:
NO
result:
ok answer is 0
Test #48:
score: 0
Accepted
time: 14ms
memory: 5732kb
input:
200000
output:
YES 1 3 2 6 4 5 7 13 9 11 10 14 8 12 15 25 17 19 27 18 26 22 30 20 28 21 29 23 16 24 31 49 33 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 42 58 46 62 40 56 44 60 47 32 48 63 97 65 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 74 106 78 110 72 104 76 108 79 111 89 121 81 113 ...
result:
ok answer is 1
Test #49:
score: 0
Accepted
time: 1ms
memory: 3832kb
input:
3073
output:
YES 1 3 2 6 4 5 7 13 9 11 10 14 8 12 15 25 17 19 27 18 26 22 30 20 28 21 29 23 16 24 31 49 33 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 42 58 46 62 40 56 44 60 47 32 48 63 97 65 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 74 106 78 110 72 104 76 108 79 111 89 121 81 113 ...
result:
ok answer is 1
Test #50:
score: 0
Accepted
time: 2ms
memory: 4128kb
input:
16383
output:
YES 1 3 2 6 4 5 7 13 9 11 10 14 8 12 15 25 17 19 27 18 26 22 30 20 28 21 29 23 16 24 31 49 33 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 42 58 46 62 40 56 44 60 47 32 48 63 97 65 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 74 106 78 110 72 104 76 108 79 111 89 121 81 113 ...
result:
ok answer is 1
Test #51:
score: 0
Accepted
time: 3ms
memory: 4128kb
input:
32767
output:
YES 1 3 2 6 4 5 7 13 9 11 10 14 8 12 15 25 17 19 27 18 26 22 30 20 28 21 29 23 16 24 31 49 33 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 42 58 46 62 40 56 44 60 47 32 48 63 97 65 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 74 106 78 110 72 104 76 108 79 111 89 121 81 113 ...
result:
ok answer is 1
Test #52:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
399
output:
YES 1 3 2 6 4 5 7 13 9 11 10 14 8 12 15 25 17 19 27 18 26 22 30 20 28 21 29 23 16 24 31 49 33 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 42 58 46 62 40 56 44 60 47 32 48 63 97 65 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 74 106 78 110 72 104 76 108 79 111 89 121 81 113 ...
result:
ok answer is 1
Test #53:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
5757
output:
NO
result:
ok answer is 0
Test #54:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
179
output:
NO
result:
ok answer is 0
Test #55:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
228
output:
YES 1 3 2 6 4 5 7 13 9 11 10 14 8 12 15 25 17 19 27 18 26 22 30 20 28 21 29 23 16 24 31 49 33 35 51 34 50 38 54 36 52 37 53 39 55 45 61 41 57 43 59 42 58 46 62 40 56 44 60 47 32 48 63 97 65 67 99 66 98 70 102 68 100 69 101 71 103 77 109 73 105 75 107 74 106 78 110 72 104 76 108 79 111 89 121 81 113 ...
result:
ok answer is 1
Extra Test:
score: 0
Extra Test Passed