Submission #372884

#TimeUsernameProblemLanguageResultExecution timeMemory
372884TraduttoreXor Sort (eJOI20_xorsort)C++14
0 / 100
1 ms364 KiB
#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}); int mn = 2e9; vector <pll> ans2; for (int j = 0;j < n;j++) { vector <int> aa; aa = a; for (int i = 0;i < n;i++) if (i != j) a[i]^=a[j]; unordered_map <int,int> mp; bool YY = true; for (int i = 0;i < n;i++) { if (mp[a[i]]) {YY = false;break;} ++mp[a[i]]; } if (YY == false) { a = aa; continue; } ans.clear(); for (int i = 0;i < n;i++) if (i != j) ans.pb({i + 1,j + 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]); } if (ans.size() < mn) { mn = ans.size(); ans2 = ans; } a = aa; } ans = ans2; } 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 (stderr)

xorsort.cpp: In function 'void solve()':
xorsort.cpp:56:14: warning: unused variable 'found' [-Wunused-variable]
   56 |         bool found = true;
      |              ^~~~~
xorsort.cpp:57:13: warning: unused variable 'mx' [-Wunused-variable]
   57 |         int mx = -1;
      |             ^~
xorsort.cpp:70:20: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   70 |     if (ans.size() < mn) {
      |         ~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...