답안 #1102052

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1102052 2024-10-17T11:11:57 Z vjudge1 Xor Sort (eJOI20_xorsort) C++17
65 / 100
7 ms 1488 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define bitcount __builtin_popcountll
using namespace std;
using namespace __gnu_pbds;
using namespace chrono;

bool has(int x, int bit) {
    return (x >> bit) & 1;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    int n,s; cin >> n >> s;
    int a[n]; for (int i = 0; i < n; cin >> a[i++]);
    vector<pair<int,int>> oper;
    auto operate = [&](int i, int j) {
        a[i] ^= a[j];
        oper.emplace_back(i+1, j+1);
    };

    if (s == 1) {
        for (int iter = 0; iter < n-1; iter++) {
            for (int i = 0; i < n-1; i++) {
                if (a[i] > a[i+1]) {
                    operate(i, i+1);
                    operate(i+1, i);
                    operate(i, i+1);
                }
            }
        }
    } else {
        for (int b = 20; b >= 0; b--) {
            for (int i = 0; i < n-1; i++) {
                if (a[i+1] >= (1 << b+1)) break;
                if (has(a[i], b) && !has(a[i+1], b)) {
                    operate(i+1, i);
                }
                if (has(a[i], b) && has(a[i+1], b)) {
                    operate(i, i+1);
                }
            }
        }
    }
    cout << oper.size() << "\n";
    for (auto [i, j] : oper) cout << i << " " << j << "\n";
}

Compilation message

xorsort.cpp: In function 'int main()':
xorsort.cpp:38:38: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   38 |                 if (a[i+1] >= (1 << b+1)) break;
      |                                     ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 3 ms 724 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 3 ms 724 KB Output is correct
9 Correct 3 ms 724 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 4 ms 980 KB Output is correct
13 Correct 7 ms 980 KB Output is correct
14 Correct 4 ms 980 KB Output is correct
15 Correct 5 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 3 ms 724 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 3 ms 724 KB Output is correct
9 Correct 3 ms 724 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 4 ms 980 KB Output is correct
13 Correct 7 ms 980 KB Output is correct
14 Correct 4 ms 980 KB Output is correct
15 Correct 5 ms 980 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 3 ms 724 KB Output is correct
18 Correct 4 ms 980 KB Output is correct
19 Correct 4 ms 980 KB Output is correct
20 Correct 3 ms 980 KB Output is correct
21 Correct 4 ms 980 KB Output is correct
22 Correct 4 ms 980 KB Output is correct
23 Correct 5 ms 980 KB Output is correct
24 Correct 5 ms 980 KB Output is correct
25 Correct 4 ms 980 KB Output is correct
26 Incorrect 7 ms 1488 KB Integer 59568 violates the range [0, 40000]
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 4 ms 980 KB Output is correct
6 Correct 4 ms 980 KB Output is correct
7 Correct 5 ms 980 KB Output is correct
8 Correct 6 ms 980 KB Output is correct
9 Correct 4 ms 980 KB Output is correct
10 Correct 4 ms 980 KB Output is correct
11 Correct 4 ms 980 KB Output is correct
12 Correct 4 ms 980 KB Output is correct
13 Correct 4 ms 992 KB Output is correct
14 Correct 4 ms 980 KB Output is correct
15 Correct 5 ms 980 KB Output is correct