Submission #465956

# Submission time Handle Problem Language Result Execution time Memory
465956 2021-08-17T12:40:36 Z Sench2006 Xor Sort (eJOI20_xorsort) C++14
0 / 100
1 ms 204 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define lb lower_bound
#define ub upper_bound

#define FOR(i, a, b) for(auto i = a; i < b; i++)
#define FORD(i, a, b) for(auto i = a - 1; i >= b; i--)
#define trav(x, v) for(auto x : v)

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

// ---------------------------------------- Solution ---------------------------------------- //

const int N = 1005;
int s, n;
int a[N];

void solve1() {

}

void solve2() {
    vector <pair<int, int>> ans;
    for(int i = 1; i <= (1 << 20); i *= 2) {
        FOR(j, 1, n) {
            if((i&a[j])) {
                if(!(i&a[j + 1])) {
                    ans.push_back({j + 1,j});
                    a[j + 1] ^= a[j];
                }
                ans.push_back({j, j + 1});
                a[j] ^= a[j + 1];
            }
        }
    }
    cout << ans.size() << endl;
    FOR(i, 0, ans.size()) {
       cout << ans[i].first << " " << ans[i].second << endl;
    }
}

void solve() {
    cin >> n >> s;
    FOR(i, 1, n + 1) {
        cin >> a[i];
    }
    // if (s == 1) solve1();
    // else solve2();
    solve2();
    FOR(i, 1, n + 1) {
        cout << a[i] << " ";
    }
    cout << "\n";
}

int main() {
    fastio;
    
    int tests = 1;
    // cin >> tests;
    while (tests--) {
        solve();
    }

    return 0;
}

Compilation message

xorsort.cpp: In function 'void solve2()':
xorsort.cpp:12:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 | #define FOR(i, a, b) for(auto i = a; i < b; i++)
......
   43 |     FOR(i, 0, ans.size()) {
      |         ~~~~~~~~~~~~~~~~                
xorsort.cpp:43:5: note: in expansion of macro 'FOR'
   43 |     FOR(i, 0, ans.size()) {
      |     ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Extra information in the output file
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Extra information in the output file
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Extra information in the output file
2 Halted 0 ms 0 KB -