답안 #465934

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
465934 2021-08-17T11:25:54 Z Alen777 Xor Sort (eJOI20_xorsort) C++14
40 / 100
65 ms 976 KB
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;

#define ll long long
#define ull unsigned ll
#define pb push_back
#define mpr make_pair
#define lb lower_bound
#define ld long double
#define ub upper_bound

map<pair<int, int>, bool> m;
int n, s;
int a[100005];

void solve() {
    cin >> n >> s;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<pair<int, int> > ans;
    for (int i = 1; i <= (1 << 20); i *= 2) {
        for (int j = 0; j < n - 1; j++) {
            if ((i & a[j]) && !(i & a[j + 1])) {
                ans.push_back(mpr(j + 1, j));
                ans.push_back(mpr(j, j + 1));
                a[j + 1] = a[j + 1] ^ a[j];
                a[j] = a[j] ^ a[j + 1];
            }
            else if (i & a[j]) {
                ans.push_back(mpr(j, j + 1));
                a[j] = a[j] ^ a[j + 1];
            }
        }
    }
    cout << ans.size() << endl;
    for (auto i : ans) {
        cout << i.first + 1 << ' ' << i.second + 1 << endl;
    }
}

int main() {
    /*cout.setf(ios::fixed | ios::showpoint);
    cout.precision(6);*/
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 3 ms 332 KB Not sorted
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 3 ms 332 KB Not sorted
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 3 ms 356 KB Output is correct
4 Correct 10 ms 460 KB Output is correct
5 Correct 54 ms 856 KB Output is correct
6 Correct 50 ms 952 KB Output is correct
7 Correct 51 ms 864 KB Output is correct
8 Correct 60 ms 896 KB Output is correct
9 Correct 52 ms 896 KB Output is correct
10 Correct 57 ms 864 KB Output is correct
11 Correct 51 ms 884 KB Output is correct
12 Correct 52 ms 864 KB Output is correct
13 Correct 53 ms 896 KB Output is correct
14 Correct 52 ms 872 KB Output is correct
15 Correct 65 ms 976 KB Output is correct