QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#304539#8004. Bit Componentucup-team228#WA 1ms7964kbC++173.1kb2024-01-13 20:56:362024-01-13 20:56:36

Judging History

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

  • [2024-01-13 20:56:36]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7964kb
  • [2024-01-13 20:56:36]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct DSU {
    static const int N = 2e5 * 20 + 10;
    int Parent[N], Rank[N], Size[N], cnt;
    void init(int n) {
        for (int i = 1; i <= n; i++) {
            Parent[i] = i, Rank[i] = 0, Size[i] = 1;
        }
        cnt = n;
    }
    int find(int v) {
        if (Parent[v] == v) return v;
        else return Parent[v] = find(Parent[v]);
    }
    void unite(int u, int v) {
        u = find(u), v = find(v);
        if (u == v) return;
        if (Rank[u] < Rank[v]) swap(u, v);
        if (Rank[v] == Rank[u]) Rank[u]++;
        Parent[v] = u, cnt--;
        Size[u] += Size[v];
    }
} dsu;

bool getbit(int mask, int bit) {
    return mask & (1 << bit);
}

bool check(int n, int b, const vector<int>& a) {
    int tot = 0;
    for (int i = 0; i < n; i++) {
        tot += __builtin_popcount(a[i]);
    }
    dsu.init(n * b);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j + 1 < b; j++) {
            if (getbit(a[i], j) && getbit(a[i], j + 1)) {
                dsu.unite(i * b + j + 1, i * b + j + 2);
            }
        }
    }
    for (int i = 0; i + 1 < n; i++) {
        for (int j = 0; j < b; j++) {
            if (getbit(a[i], j) && getbit(a[i + 1], j)) {
                dsu.unite(i * b + j + 1, (i + 1) * b + j + 1);
            }
        }
    }
    return n * b - tot + 1 == dsu.cnt;
}

void foo() {
    const int n = 9;
    const int b = 6;
    vector<int> a(n);
    iota(a.begin(), a.end(), 1);
    bool ok = false;
    do {
        if (check(n, b, a)) {
            cout << "YES\n";
            for (int x : a) {
                cout << x << "\t" << bitset<b>(x) << "\n";
            }
            ok = true;
            break;
        }
    } while (next_permutation(a.begin(), a.end()));
    if (!ok) {
        cout << "NO\n";
    }
    exit(0);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    // foo();

    int n;
    cin >> n;
    vector<int> ans = {1, 3, 2, 6, 4, 5, 7};
    bool ok = false;
    while (ans.size() < max(4 * n, 100)) {
        vector<int> tmp = ans;
        reverse(tmp.begin(), tmp.end());
        for (int& x : ans) {
            x <<= 1;
        }
        for (int x : tmp) {
            ans.push_back((x << 1) | 1);
        }
        ans.push_back(1);
        if (ans.size() >= n) {
            vector<int> cur;
            for (int x : ans) {
                if (x <= n) {
                    cur.push_back(x);
                }
            }
            if (check(n, 20, cur)) {
                cout << "YES\n";
                for (int x : cur) {
                    cout << x << " ";
                }
                cout << "\n";
                ok = true;
                break;
            }
        }
    }
    if (!ok) {
        cout << "NO\n";
    }

#ifdef LOCAL
    cout << "\nTime elapsed: " << double(clock()) / CLOCKS_PER_SEC << " s.\n";
#endif
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1

output:

YES
1 

result:

ok answer is 1

Test #2:

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

input:

2

output:

NO

result:

ok answer is 0

Test #3:

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

input:

3

output:

YES
2 3 1 

result:

ok answer is 1

Test #4:

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

input:

4

output:

NO

result:

ok answer is 0

Test #5:

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

input:

5

output:

NO

result:

ok answer is 0

Test #6:

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

input:

6

output:

NO

result:

ok answer is 0

Test #7:

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

input:

7

output:

YES
2 6 4 5 7 3 1 

result:

ok answer is 1

Test #8:

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

input:

8

output:

NO

result:

ok answer is 0

Test #9:

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

input:

9

output:

NO

result:

ok answer is 0

Test #10:

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

input:

10

output:

NO

result:

ok answer is 0

Test #11:

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

input:

11

output:

NO

result:

ok answer is 0

Test #12:

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

input:

12

output:

NO

result:

ok answer is 0

Test #13:

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

input:

13

output:

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

result:

ok answer is 1

Test #14:

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

input:

14

output:

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

result:

ok answer is 1

Test #15:

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

input:

15

output:

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

result:

ok answer is 1

Test #16:

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

input:

16

output:

NO

result:

ok answer is 0

Test #17:

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

input:

17

output:

NO

result:

ok answer is 0

Test #18:

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

input:

23

output:

NO

result:

ok answer is 0

Test #19:

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

input:

24

output:

NO

result:

ok answer is 0

Test #20:

score: -100
Wrong Answer
time: 1ms
memory: 7672kb

input:

25

output:

NO

result:

wrong answer Jury has the answer, participant doesn't