Submission #958592

# Submission time Handle Problem Language Result Execution time Memory
958592 2024-04-06T05:28:25 Z 12345678 Sorting (IOI15_sorting) C++17
54 / 100
2 ms 604 KB
#include "sorting.h"
#include <bits/stdc++.h>
 
using namespace std;
 
const int nx=505;
 
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    int idx[nx], s[nx];
    for (int i=0; i<N; i++) idx[i]=i, s[i]=S[i];
    for (int i=N-1; i>=0; i--) swap(idx[X[i]], idx[Y[i]]);
    for (int i=0; i<N; i++)
    {
        swap(idx[X[i]], idx[Y[i]]);
        swap(s[X[i]], s[Y[i]]);
        for (int j=0; j<N; j++) if (idx[j]==i) P[i]=j;
        for (int j=0; j<N; j++) 
        {
            if (s[j]==i) 
            {
                Q[i]=j;
                swap(s[P[i]], s[Q[i]]);
                break;
            }
        }
    }
    for (int i=0; i<N; i++)
    {
        swap(S[X[i]], S[Y[i]]);
        swap(S[P[i]], S[Q[i]]);
        bool sorted=1;
        for (int j=0; j<N; j++) if (S[j]!=j) sorted=0;
        if (sorted) return i+1;
    }
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:8:39: warning: unused parameter 'M' [-Wunused-parameter]
    8 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                   ~~~~^
sorting.cpp:35:1: warning: control reaches end of non-void function [-Wreturn-type]
   35 | }
      | ^
# 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 1 ms 504 KB Output is correct
6 Correct 0 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 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 1 ms 504 KB Output is correct
6 Correct 0 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 1 ms 344 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 1 ms 344 KB Output is correct
2 Correct 1 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 1 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 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 1 ms 504 KB Output is correct
6 Correct 0 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 1 ms 344 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 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 1 ms 560 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -