fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. mt19937_64 rd(time(0));
  5. int rand(int L, int R){
  6. return L + rd() % (R - L + 1);
  7. }
  8.  
  9. void chaos_sort(int* arr, int length){
  10. for(int i = 0; i < length; i += rand(0, length - 1)){
  11. int pos = rand(0, length - 1);
  12. if(arr[min(i, pos)] < arr[max(i, pos)]) swap(arr[min(i, pos)], arr[max(i, pos)]);
  13. }
  14. }
  15.  
  16. bool isSorted(int* arr, int length){
  17. for(int i = 1; i < length; i++){
  18. if(arr[i - 1] < arr[i]) return 0;
  19. }
  20.  
  21. return 1;
  22. }
  23.  
  24. int n, arr[10000];
  25.  
  26. int main(){
  27. ios_base::sync_with_stdio(0);
  28. cin.tie(0); cout.tie(0);
  29.  
  30. cin >> n;
  31. for(int i = 0; i < n; i++) cin >> arr[i];
  32.  
  33. while(!isSorted(arr, n)){
  34. chaos_sort(arr, n);
  35. }
  36.  
  37. for(int i = 0; i < n; i++) cout << arr[i] << ' ';
  38.  
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty