답안 #774893

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
774893 2023-07-06T05:03:13 Z vjudge1 Xor Sort (eJOI20_xorsort) C++14
100 / 100
6 ms 1492 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define sumof(x) accumulate(all(x), 0ll)
 
const int N=1001;
int n, s, a[N];
 
void solve(int tc){
    // cout << "Case #" << tc << ": ";
    vector<pair<int, int>> v;
    cin >> n >> s;
    for (int i=1; i<=n; ++i) cin >> a[i];
    if (n<=200){
        vector<int> vv(a+1, a+n+1);
        for (int i=1; i<n; ++i) v.emplace_back(i, i+1);
        int m=n;
        for (int i=1; i<m; ++i){
            int j=max_element(all(vv))-vv.begin()+1;
            for (int k=j; k<n; ++k) v.emplace_back(k+1, k);
            for (int k=max(1ll, j-1); k<n; ++k) v.emplace_back(k, k+1);
            vv.erase(vv.begin()+j-1);
            --n;
        }
        cout << sz(v) << '\n';
        for (auto& i:v) cout << i.first << ' ' << i.second << '\n';
        return;
    }
    for (int i=19; i>=0; --i){
        vector<int> idx;
        for (int j=1; j<=n; ++j) if (a[j]>>i&1) idx.push_back(j);
        if (idx.empty()) continue;
        for (int j=1; j<sz(idx); ++j){
            int i1=idx[j-1], i2=idx[j];
            for (int k=i1; k<i2-1; ++k){
                v.emplace_back(k+1, k);
                a[k+1]^=a[k];
                v.emplace_back(k, k+1);
                a[k]^=a[k+1];
            }
            v.emplace_back(i2-1, i2);
            a[i2-1]^=a[i2];
        }
        if (idx.back()!=n){
            for (int j=idx.back(); j<n; ++j){
                v.emplace_back(j+1, j);
                a[j+1]^=a[j];
                v.emplace_back(j, j+1);
                a[j]^=a[j+1];
            }
        }
        --n;
    }
    cout << sz(v) << '\n';
    for (auto& i:v) cout << i.first << ' ' << i.second << '\n';
}
 
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int ntests=1;
    // cin >> ntests;
    for (int i=1; i<=ntests; ++i) solve(i);
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 2 ms 716 KB Output is correct
5 Correct 2 ms 728 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 728 KB Output is correct
10 Correct 2 ms 728 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 3 ms 856 KB Output is correct
13 Correct 3 ms 984 KB Output is correct
14 Correct 4 ms 984 KB Output is correct
15 Correct 3 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 2 ms 716 KB Output is correct
5 Correct 2 ms 728 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 728 KB Output is correct
10 Correct 2 ms 728 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 3 ms 856 KB Output is correct
13 Correct 3 ms 984 KB Output is correct
14 Correct 4 ms 984 KB Output is correct
15 Correct 3 ms 856 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 2 ms 728 KB Output is correct
18 Correct 3 ms 856 KB Output is correct
19 Correct 3 ms 984 KB Output is correct
20 Correct 3 ms 856 KB Output is correct
21 Correct 3 ms 984 KB Output is correct
22 Correct 3 ms 984 KB Output is correct
23 Correct 4 ms 868 KB Output is correct
24 Correct 3 ms 856 KB Output is correct
25 Correct 3 ms 896 KB Output is correct
26 Correct 5 ms 1492 KB Output is correct
27 Correct 5 ms 1492 KB Output is correct
28 Correct 6 ms 1492 KB Output is correct
29 Correct 5 ms 1492 KB Output is correct
30 Correct 5 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 3 ms 984 KB Output is correct
5 Correct 4 ms 1100 KB Output is correct
6 Correct 6 ms 1104 KB Output is correct
7 Correct 6 ms 1104 KB Output is correct
8 Correct 4 ms 1100 KB Output is correct
9 Correct 4 ms 1104 KB Output is correct
10 Correct 5 ms 1088 KB Output is correct
11 Correct 4 ms 1104 KB Output is correct
12 Correct 4 ms 1232 KB Output is correct
13 Correct 4 ms 1220 KB Output is correct
14 Correct 4 ms 1104 KB Output is correct
15 Correct 5 ms 1492 KB Output is correct