Submission #775797

# Submission time Handle Problem Language Result Execution time Memory
775797 2023-07-07T02:23:23 Z khanhphucscratch Xor Sort (eJOI20_xorsort) C++14
100 / 100
9 ms 984 KB
#include<bits/stdc++.h>
using namespace std;
vector<pair<int, int>> tt;
int a[1001], re[1001];
void op(int i, int j)
{
    tt.push_back(make_pair(i, j));
    a[i] ^= a[j];
}
bool getbit(int num, int bit)
{
    return (num >> bit)&1;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, s;
    cin>>n>>s;
    for(int i = 1; i <= n; i++) cin>>a[i];
    if(s == 2){
        int last = n;
        for(int bit = 19; bit >= 0; bit--){
            int c = 0;
            for(int i = 1; i <= last; i++) if(getbit(a[i], bit) == 1) c = i;
            if(c == 0) continue;
            for(int i = c-1; i >= 1; i--) if(getbit(a[i], bit) == 0) op(i, i+1);
            for(int i = c+1; i <= last; i++) if(getbit(a[i], bit) == 0) op(i, i-1);
            for(int i = 2; i <= last; i++) op(i-1, i);
            last--;
        }
    }
    else{
        for(int i = 1; i <= n; i++) re[i] = a[i];
        for(int i = 1; i < n; i++) op(i, i+1);
        int cur = n;
        for(int i = 1; i <= n; i++){
            int place = 1;
            for(int j = 2; j <= cur; j++) if(re[place] < re[j]) place = j;
            for(int j = place; j < cur; j++) op(j+1, j);
            for(int j = max(place-1, 1); j < cur; j++) op(j, j+1);
            for(int j = place; j < cur; j++) swap(re[j], re[j+1]);
            cur--;
        }
    }
    /*for(int i = 1; i <= n; i++) cout<<a[i]<<" ";
    cout<<'\n';*/
    cout<<tt.size()<<'\n';
    for(int i = 0; i < tt.size(); i++) cout<<tt[i].first<<" "<<tt[i].second<<'\n';
}

Compilation message

xorsort.cpp: In function 'int main()':
xorsort.cpp:49:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     for(int i = 0; i < tt.size(); i++) cout<<tt[i].first<<" "<<tt[i].second<<'\n';
      |                    ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 584 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 3 ms 580 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 3 ms 728 KB Output is correct
13 Correct 3 ms 728 KB Output is correct
14 Correct 3 ms 728 KB Output is correct
15 Correct 3 ms 728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 584 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 3 ms 580 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 3 ms 728 KB Output is correct
13 Correct 3 ms 728 KB Output is correct
14 Correct 3 ms 728 KB Output is correct
15 Correct 3 ms 728 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 2 ms 576 KB Output is correct
18 Correct 4 ms 728 KB Output is correct
19 Correct 3 ms 728 KB Output is correct
20 Correct 3 ms 716 KB Output is correct
21 Correct 4 ms 728 KB Output is correct
22 Correct 3 ms 712 KB Output is correct
23 Correct 3 ms 728 KB Output is correct
24 Correct 3 ms 728 KB Output is correct
25 Correct 3 ms 712 KB Output is correct
26 Correct 5 ms 984 KB Output is correct
27 Correct 5 ms 984 KB Output is correct
28 Correct 5 ms 984 KB Output is correct
29 Correct 5 ms 984 KB Output is correct
30 Correct 5 ms 984 KB Output is correct
# Verdict Execution time Memory 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 1 ms 468 KB Output is correct
5 Correct 4 ms 856 KB Output is correct
6 Correct 9 ms 828 KB Output is correct
7 Correct 5 ms 856 KB Output is correct
8 Correct 4 ms 856 KB Output is correct
9 Correct 4 ms 856 KB Output is correct
10 Correct 4 ms 856 KB Output is correct
11 Correct 4 ms 856 KB Output is correct
12 Correct 4 ms 980 KB Output is correct
13 Correct 4 ms 856 KB Output is correct
14 Correct 4 ms 856 KB Output is correct
15 Correct 5 ms 984 KB Output is correct