QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#304531#8004. Bit Componentucup-team228#WA 1ms5536kbC++172.9kb2024-01-13 20:52:452024-01-13 20:52:46

Judging History

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

  • [2024-01-13 20:52:46]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5536kb
  • [2024-01-13 20:52:45]
  • 提交

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};
    while (ans.size() < n) {
        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);
    }
    vector<int> tmp;
    for (int x : ans) {
        if (x <= n) {
            // cout << "+ " << x << "\n";
            tmp.push_back(x);
        } else {
            // cout << "- " << x << "\n";
        }
    }
    swap(ans, tmp);
    if (check(n, 20, ans)) {
        cout << "YES\n";
        for (int x : ans) {
            cout << x << " ";
        }
        cout << "\n";
    } else {
        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: 5536kb

input:

1

output:

YES
1 

result:

ok answer is 1

Test #2:

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

input:

2

output:

NO

result:

ok answer is 0

Test #3:

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

input:

3

output:

YES
1 3 2 

result:

ok answer is 1

Test #4:

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

input:

4

output:

NO

result:

ok answer is 0

Test #5:

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

input:

5

output:

NO

result:

ok answer is 0

Test #6:

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

input:

6

output:

NO

result:

ok answer is 0

Test #7:

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

input:

7

output:

YES
1 3 2 6 4 5 7 

result:

ok answer is 1

Test #8:

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

input:

8

output:

NO

result:

ok answer is 0

Test #9:

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

input:

9

output:

NO

result:

ok answer is 0

Test #10:

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

input:

10

output:

NO

result:

ok answer is 0

Test #11:

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

input:

11

output:

NO

result:

ok answer is 0

Test #12:

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

input:

12

output:

NO

result:

ok answer is 0

Test #13:

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

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: 0ms
memory: 3468kb

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: 0ms
memory: 3456kb

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: 0ms
memory: 3460kb

input:

16

output:

NO

result:

ok answer is 0

Test #17:

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

input:

17

output:

NO

result:

ok answer is 0

Test #18:

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

input:

23

output:

NO

result:

ok answer is 0

Test #19:

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

input:

24

output:

NO

result:

ok answer is 0

Test #20:

score: -100
Wrong Answer
time: 0ms
memory: 3468kb

input:

25

output:

NO

result:

wrong answer Jury has the answer, participant doesn't