Submission #1096509

# Submission time Handle Problem Language Result Execution time Memory
1096509 2024-10-04T16:35:34 Z onlk97 Sorting (IOI15_sorting) C++14
36 / 100
17 ms 604 KB
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]){
    int r;
    int a[N];
    for (int i=0; i<N; i++) a[i]=S[i];
    for (int i=0; i<M; i++){
        swap(a[X[i]],a[Y[i]]);
        bool vis[N];
        for (int j=0; j<N; j++) vis[j]=0;
        int cnt=0;
        for (int j=0; j<N; j++){
            if (vis[j]) continue;
            cnt++;
            int tp=j;
            while (!vis[tp]){
                vis[tp]=1;
                tp=a[tp];
            }
        }
        if (N-cnt<=i+1){
            r=i+1;
            break;
        }
    }
    bool allsame=1;
    for (int i=0; i<N; i++) if (S[i]!=i) allsame=0;
    if (allsame) r=0;
    for (int i=0; i<r; i++){
        swap(S[X[i]],S[Y[i]]);
        bool stillhave[N];
        for (int j=0; j<N; j++) stillhave[j]=0;
        for (int j=i+1; j<r; j++){
            if (X[j]==Y[j]) continue;
            stillhave[X[j]]=1; stillhave[Y[j]]=1;
        }
        int haha=-1;
        for (int j=0; j<N; j++){
            if (!stillhave[j]&&S[j]!=j) haha=j;
        }
        if (haha==-1){
            P[i]=0; Q[i]=0;
            continue;
        }
        for (int j=0; j<N; j++) if (S[j]==haha) P[i]=j;
        Q[i]=haha;
        swap(S[P[i]],S[Q[i]]);
    }
    return r;
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:34:26: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   34 |         for (int j=i+1; j<r; j++){
      |                         ~^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 344 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 344 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 344 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 344 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 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 344 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 344 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 1 ms 348 KB Output is correct
13 Correct 1 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 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 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 Incorrect 2 ms 604 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -