fork(1) download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t; cin>>t;
  5. while(t--){
  6. int n;
  7. cin >> n;
  8. int A[n];
  9. for (int i = 0; i < n; i++) cin >> A[i];
  10. int cnter = 1;
  11. while (!is_sorted(A, A + n)) {
  12. if (cnter % 2) {
  13. for (int i = 0; i < n - 1; i++) {
  14. if (((i + 1) % 2) and A[i] > A[i + 1])
  15. swap(A[i], A[i + 1]);
  16. }
  17. }
  18. else {
  19. for (int i = 0; i < n - 1; i++) {
  20. if (!((i + 1) % 2) and A[i] > A[i + 1])
  21. swap(A[i], A[i + 1]);
  22. }
  23. }
  24. cnter++;
  25. }
  26. cout << cnter - 1<< endl;
  27. }
  28. return 0;
  29. }
Time limit exceeded #stdin #stdout 5s 5348KB
stdin
Standard input is empty
stdout
32749
32748