Submission #372882

# Submission time Handle Problem Language Result Execution time Memory
372882 2021-03-02T07:35:22 Z Traduttore Xor Sort (eJOI20_xorsort) C++17
0 / 100
237 ms 18360 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define pll pair <ll,ll>
#define F first
#define S second
#define int ll
#define pb push_back
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
using namespace __gnu_pbds;
typedef tree <pll,null_type,less <pll>,rb_tree_tag,tree_order_statistics_node_update> orduk;
typedef tree <ll,null_type,less <ll>,rb_tree_tag,tree_order_statistics_node_update> orduk2;
ll n,type;
vector <ll> a;
inline void init() {
    cin>>n>>type;
    a.resize(n);
    for (int i = 0;i < n;i++)
        cin>>a[i];
}
vector <pll> ans;
inline void output() {
    cout<<ans.size()<<'\n';
    for (auto to:ans)
        cout<<to.F<<" "<<to.S<<'\n';
    exit(0);
}
inline void solve() {
	for (int i = 0;i < n - 1;i++)
	ans.pb({i + 1,i + 2});
	for (int i = 0;i < n - 1;i++)
	a[i]=(a[i] ^ a[i + 1]);
    while (1) {
        bool found = true;
        int mx = -1;
        int pos = -1;
        for (int i = 0;i < n - 1;i++)
        if (a[i] > a[i + 1]) {
        	pos = i;
        	break;
        }
        if (pos < 0) break;
            ans.pb({pos + 2,pos + 1});
            ans.pb({pos + 1, pos + 2});
            ans.pb({pos + 2,pos + 1});
            swap(a[pos],a[pos + 1]);
    }
    for (int i = 0;i < n - 1;i++)
    if (a[i] > a[i + 1]) {
    	cout<<"XX";exit(0);
    }
}

int32_t main() {
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
IOS;
int m;
m = 10;
m-=9;
while (m--)
{
    init();
    solve();
    output();
}
}
/*written by Traduttore*/
/*waiting for a miracle...*/

Compilation message

xorsort.cpp: In function 'void solve()':
xorsort.cpp:37:14: warning: unused variable 'found' [-Wunused-variable]
   37 |         bool found = true;
      |              ^~~~~
xorsort.cpp:38:13: warning: unused variable 'mx' [-Wunused-variable]
   38 |         int mx = -1;
      |             ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 4 ms 880 KB Output is correct
5 Incorrect 4 ms 1008 KB Not sorted
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 4 ms 880 KB Output is correct
5 Incorrect 4 ms 1008 KB Not sorted
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 7 ms 1132 KB Output is correct
5 Incorrect 237 ms 18360 KB Integer 754956 violates the range [0, 40000]
6 Halted 0 ms 0 KB -