Submission #442570

# Submission time Handle Problem Language Result Execution time Memory
442570 2021-07-08T08:21:41 Z Theo830 Xor Sort (eJOI20_xorsort) C++17
60 / 100
10 ms 1484 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
int main(void){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n,s;
    cin>>n>>s;
    ll arr[n];
    f(i,0,n){
        cin>>arr[i];
    }
    vector<ii>ans;
    if(s == 1){
        ll pre = 0;
        f(j,0,n){
            ll maxi = -1;
            ll pos = 0;
            f(i,0,n-j){
                maxi = max(maxi,arr[i] ^ pre);
                if(maxi == (arr[i] ^ pre)){
                    pos = i;
                }
            }
            pre = maxi;
            f(i,0,n-j-1){
                ans.pb(ii(i+1,i+2));
                arr[i] ^= arr[i+1];
            }
            f(i,pos,n-j-1){
                ans.pb(ii(i+2,i+1));
                arr[i+1] ^= arr[i];
            }
            for(ll i = pos-1;i >= 1;i--){
                ans.pb(ii(i,i+1));
                arr[i-1] ^= arr[i];
            }
        }
        for(ll i = n-2;i >= 0;i--){
            ans.pb(ii(i+1,i+2));
            arr[i] ^= arr[i+1];
        }
        assert(is_sorted(arr,arr+n));
    }
    cout<<ans.size()<<"\n";
    for(auto x:ans){
        cout<<x.F<<" "<<x.S<<"\n";
    }
}
/*
5 1
3 2 8 4 1
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 5 ms 976 KB Output is correct
5 Correct 5 ms 864 KB Output is correct
6 Correct 5 ms 928 KB Output is correct
7 Correct 5 ms 976 KB Output is correct
8 Correct 5 ms 976 KB Output is correct
9 Correct 5 ms 848 KB Output is correct
10 Correct 5 ms 848 KB Output is correct
11 Correct 5 ms 976 KB Output is correct
12 Correct 7 ms 848 KB Output is correct
13 Correct 5 ms 976 KB Output is correct
14 Correct 5 ms 892 KB Output is correct
15 Correct 5 ms 976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 5 ms 976 KB Output is correct
5 Correct 5 ms 864 KB Output is correct
6 Correct 5 ms 928 KB Output is correct
7 Correct 5 ms 976 KB Output is correct
8 Correct 5 ms 976 KB Output is correct
9 Correct 5 ms 848 KB Output is correct
10 Correct 5 ms 848 KB Output is correct
11 Correct 5 ms 976 KB Output is correct
12 Correct 7 ms 848 KB Output is correct
13 Correct 5 ms 976 KB Output is correct
14 Correct 5 ms 892 KB Output is correct
15 Correct 5 ms 976 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 5 ms 976 KB Output is correct
18 Correct 8 ms 1484 KB Output is correct
19 Correct 8 ms 1484 KB Output is correct
20 Correct 8 ms 1484 KB Output is correct
21 Correct 8 ms 1460 KB Output is correct
22 Correct 9 ms 1484 KB Output is correct
23 Correct 10 ms 1484 KB Output is correct
24 Correct 8 ms 1484 KB Output is correct
25 Correct 8 ms 1484 KB Output is correct
26 Correct 8 ms 1484 KB Output is correct
27 Correct 8 ms 1484 KB Output is correct
28 Correct 8 ms 1484 KB Output is correct
29 Correct 8 ms 1484 KB Output is correct
30 Correct 8 ms 1484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Not sorted
2 Halted 0 ms 0 KB -