Submission #1096507

# Submission time Handle Problem Language Result Execution time Memory
1096507 2024-10-04T16:33:33 Z onlk97 Sorting (IOI15_sorting) C++14
0 / 100
18 ms 444 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++){
            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]==i) P[i]=j;
        Q[i]=i;
        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 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 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Incorrect 0 ms 344 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Incorrect 0 ms 344 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Incorrect 0 ms 344 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 444 KB Output isn't correct
2 Halted 0 ms 0 KB -