Submission #1018567

# Submission time Handle Problem Language Result Execution time Memory
1018567 2024-07-10T06:55:59 Z huutuan Sorting (IOI15_sorting) C++14
54 / 100
1000 ms 2624 KB
#include "sorting.h"

#include <bits/stdc++.h>

using namespace std;

int a[200010], pos[200010], s[200010];

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
   if (is_sorted(S, S+N)) return 0;
   for (int _=0; _<M; ++_){
      for (int i=0; i<N; ++i) s[i]=S[i];
      for (int i=0; i<N; ++i) pos[s[i]]=i;
      iota(a, a+N, 0);
      for (int i=_; i>=0; --i) swap(a[X[i]], a[Y[i]]);
      for (int i=0; i<=_; ++i){
         P[i]=Q[i]=0;
         swap(a[X[i]], a[Y[i]]);
         swap(s[X[i]], s[Y[i]]);
         pos[s[X[i]]]=X[i];
         pos[s[Y[i]]]=Y[i];
         if (is_sorted(s, s+N)){
            return i+1;
         }
         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;
         }
      }
      if (is_sorted(s, s+N)) return _+1;
   }
   return -1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 2496 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 2496 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 2492 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 432 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 2496 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 2492 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 432 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 10 ms 2392 KB Output is correct
22 Correct 8 ms 2396 KB Output is correct
23 Correct 10 ms 2624 KB Output is correct
24 Correct 7 ms 2620 KB Output is correct
25 Correct 2 ms 2396 KB Output is correct
26 Correct 5 ms 2396 KB Output is correct
27 Correct 18 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 383 ms 508 KB Output is correct
2 Execution timed out 1057 ms 2396 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 383 ms 508 KB Output is correct
2 Execution timed out 1057 ms 2396 KB Time limit exceeded
3 Halted 0 ms 0 KB -