답안 #579954

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
579954 2022-06-20T10:38:10 Z drdilyor Xor Sort (eJOI20_xorsort) C++17
65 / 100
9 ms 1344 KB
#if defined(ONPC) && !defined(_GLIBCXX_ASSERTIONS)
    #define _GLIBCXX_ASSERTIONS
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#ifdef ONPC
    #include "t_debug.cpp"
#else
    #define debug(...) 42
#endif
#define allit(a) (a).begin(), (a).end()
#define sz(a) ((int) (a).size())

using namespace std;
using ll = long long;
using vi = vector<int>;
namespace pd = __gnu_pbds;
template<typename K>
using ordered_set = pd::tree<K, pd::null_type, less<int>, pd::rb_tree_tag, pd::tree_order_statistics_node_update>;
template<typename... T>
using gp_hash_table = pd::gp_hash_table<T...>;//simple using statement gives warnings

const int INF = 1e9;
const ll INFL = 1e18;
const int N = 1e5;
const int K = 20; // 20
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);

int solve() {
#define DO(i, j) {res.emplace_back(i, j); a[i] ^= a[j];}
    int n, s; cin >> n >> s;
    vi a(n); for (auto& i : a) cin >> i;

    vector<pair<int,int>> res;
    if (s == 2) {
        int found_count = 0;

        for (int b = 1 << K; b >= 1; b >>= 1) {
            //move bit to end
            int found = 0;
            for (int i = 0; i < n - found_count - 1; i++) {
                if (a[i] & b) {
                    found = 1;
                    if (!(a[i+1] & b)) { DO(i+1, i); }
                    DO(i, i+1);
                }
            }
            found_count += found;
        }
    } else {
        for (int i = 0; i < n; i++) {
            for (int j = n-1; j > i; j--) {
                if (a[j-1] >= a[j]) {
                    DO(j-1, j);
                    DO(j, j-1);
                    DO(j-1, j);
                }
            }
        }
    }
#ifdef ONPC
    debug(a);
    for (int i = 0; i < n-1; i++) {
        assert(s == 1 ? a[i] < a[i+1] : a[i] <= a[i+1]);
    }
#endif
//#ifndef ONPC
    cout << res.size() << '\n';
    for (auto [i, j] : res) cout << i+1 << ' ' << j+1 << '\n';
//#endif
    return 0;
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
#ifdef ONPC
    cin >> t;
#endif
    while (t-- && cin) {
        if (solve()) break;
        #ifdef ONPC
            cout << "____________________" << endl;
        #endif
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 3 ms 716 KB Output is correct
6 Correct 3 ms 600 KB Output is correct
7 Correct 4 ms 728 KB Output is correct
8 Correct 3 ms 600 KB Output is correct
9 Correct 3 ms 724 KB Output is correct
10 Correct 3 ms 600 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 5 ms 856 KB Output is correct
13 Correct 6 ms 984 KB Output is correct
14 Correct 5 ms 984 KB Output is correct
15 Correct 6 ms 964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 3 ms 716 KB Output is correct
6 Correct 3 ms 600 KB Output is correct
7 Correct 4 ms 728 KB Output is correct
8 Correct 3 ms 600 KB Output is correct
9 Correct 3 ms 724 KB Output is correct
10 Correct 3 ms 600 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 5 ms 856 KB Output is correct
13 Correct 6 ms 984 KB Output is correct
14 Correct 5 ms 984 KB Output is correct
15 Correct 6 ms 964 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 3 ms 600 KB Output is correct
18 Correct 6 ms 856 KB Output is correct
19 Correct 5 ms 856 KB Output is correct
20 Correct 5 ms 856 KB Output is correct
21 Correct 6 ms 896 KB Output is correct
22 Correct 5 ms 840 KB Output is correct
23 Correct 5 ms 856 KB Output is correct
24 Correct 5 ms 856 KB Output is correct
25 Correct 5 ms 856 KB Output is correct
26 Incorrect 9 ms 1344 KB Integer 59568 violates the range [0, 40000]
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 5 ms 856 KB Output is correct
6 Correct 5 ms 856 KB Output is correct
7 Correct 5 ms 856 KB Output is correct
8 Correct 5 ms 856 KB Output is correct
9 Correct 5 ms 856 KB Output is correct
10 Correct 5 ms 856 KB Output is correct
11 Correct 5 ms 856 KB Output is correct
12 Correct 5 ms 856 KB Output is correct
13 Correct 6 ms 864 KB Output is correct
14 Correct 6 ms 856 KB Output is correct
15 Correct 6 ms 980 KB Output is correct