Submission #1018543

# Submission time Handle Problem Language Result Execution time Memory
1018543 2024-07-10T06:39:15 Z huutuan Sorting (IOI15_sorting) C++14
54 / 100
15 ms 856 KB
#include "sorting.h"

#include <bits/stdc++.h>

using namespace std;

int a[200010], pos[200010];

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
   iota(a, a+N, 0);
   for (int i=0; i<N; ++i) pos[S[i]]=i;
   for (int i=M-1; i>=0; --i) swap(a[X[i]], a[Y[i]]);
   if (is_sorted(S, S+N)) return 0;
   for (int i=0; i<M; ++i){
      P[i]=Q[i]=0;
      swap(a[X[i]], a[Y[i]]);
      if (is_sorted(S, S+N)) return i+1;
      swap(S[X[i]], S[Y[i]]);
      pos[S[X[i]]]=X[i];
      pos[S[Y[i]]]=Y[i];
      for (int j=0; j<N; ++j) if (a[j]!=S[j]){
         int k=pos[a[j]];
         if (S[j]==a[k]){
            P[i]=j, Q[i]=k;
            break;
         }
      }
      if (!P[i] && !Q[i]){
         for (int j=0; j<N; ++j) if (a[j]!=S[j]){
            int k=pos[a[j]];
            P[i]=j, Q[i]=k;
            break;
         }
      }
      swap(S[P[i]], S[Q[i]]);
      pos[S[P[i]]]=P[i];
      pos[S[Q[i]]]=Q[i];
      if (is_sorted(S, S+N)) return i+1;
   }
   for (int j=0; j<N; ++j) assert(S[j]==j);
   return M;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 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 436 KB Output is correct
6 Correct 1 ms 344 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 344 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 436 KB Output is correct
6 Correct 1 ms 344 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 344 KB Output is correct
10 Correct 0 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 1 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
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 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 436 KB Output is correct
6 Correct 1 ms 344 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 344 KB Output is correct
10 Correct 0 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 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 11 ms 628 KB Output is correct
22 Correct 11 ms 600 KB Output is correct
23 Correct 12 ms 648 KB Output is correct
24 Correct 12 ms 732 KB Output is correct
25 Correct 14 ms 856 KB Output is correct
26 Correct 11 ms 604 KB Output is correct
27 Correct 11 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -