Submission #1053810

# Submission time Handle Problem Language Result Execution time Memory
1053810 2024-08-11T17:53:56 Z Osplei Sorting (IOI15_sorting) C++17
20 / 100
1 ms 348 KB
    #include "sorting.h"
    #include <bits/stdc++.h>
     
    using namespace std;
     
    #define pb push_back
     
    typedef long long ll;
    typedef pair <ll, ll> LL;
     
    int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
     
      vector <int> orden;
      int ans = 0, pos = 0;
     
      for (int i = 0; i < N; i++) {
        orden.pb(S[i]);
      }
     
      sort(orden.begin(), orden.end());
     
      for (int i = 0; i < N; i++) {
     
        if (orden[i] != S[i]) {
          
          ans++;
          
          swap(S[X[pos]], S[Y[pos]]);
          
          for (int j = i; j < N; j++) {
            if (orden[i] == S[j]) {
     
              swap(S[i], S[j]);
     
              P[pos] = i;
              Q[pos] = j;
     
              pos++;
     
              break;
            }
          }
        }
     
      }

      for (int i = 0; i < N; i++) {
     
        if (orden[i] != S[i]) {
          
          ans++;
          
          swap(S[X[pos]], S[Y[pos]]);
          
          for (int j = i; j < N; j++) {
            if (orden[i] == S[j]) {
     
              swap(S[i], S[j]);
     
              P[pos] = i;
              Q[pos] = j;
     
              pos++;
     
              break;
            }
          }
        }
     
      }

      if (N != 1 && S[0] > S[1]) {
        ans++;
        P[pos] = 0;
        Q[pos] = 0;
        pos++;
      } 

      for (int i = 0; i < N; i++) {
     
        if (orden[i] != S[i]) {
          
          ans++;
          
          swap(S[X[pos]], S[Y[pos]]);
          
          for (int j = i; j < N; j++) {
            if (orden[i] == S[j]) {
     
              swap(S[i], S[j]);
     
              P[pos] = i;
              Q[pos] = j;
     
              pos++;
     
              break;
            }
          }
        }
     
      }
     
      if (N != 1 && S[0] > S[1]) {
        ans++;
        P[pos] = 0;
        Q[pos] = 0;
        pos++;
      } 
     
      return ans;
    }

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:11:43: warning: unused parameter 'M' [-Wunused-parameter]
   11 |     int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                       ~~~~^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Incorrect 0 ms 348 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -