Submission #600030

# Submission time Handle Problem Language Result Execution time Memory
600030 2022-07-20T12:01:58 Z PiejanVDC Sorting (IOI15_sorting) C++17
0 / 100
1000 ms 432 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[]) {
    auto sorted = [&] () -> bool {
        for(int i = 0 ; i < n ; i++)
            if(s[i] != i)
                return 0;
        return 1;
    };
    for(int T = 1 ; T <= m ; T++) {
        vector<int>c(n);
        for(int i = 0 ; i < n ; i++) c[i]= i;
        for(int i = 0 ; i < T ; i++)
            swap(c[X[i]], c[Y[i]]);
        vector<int>go(n, -1);
        for(int i = 0 ; i < n ; i++) {
            assert(go[c[i]] == -1);
            go[c[i]] = i;
        }
        vector<int>v(n);
        auto S = [&] (int W) {
            for(int i = 0 ; i < n ; i++)
                if(v[i] == W)
                    return i;
            //assert(0);
        };
        for(int i = 0 ; i < n ; i++) v[i] = s[i];
        int cnt = 0;
        for(int i = 0 ; i < T ; i++) {
            cnt++;
            swap(v[X[i]], v[Y[i]]);
            swap(go[X[i]], go[Y[i]]);
            int j;
            for(j = 0 ; j < n ; j++) {
                if(go[j] != v[j]) {
                    int p = S(go[j]);
                    P[cnt-1] = p;
                    Q[cnt-1] = i;
                    swap(v[p], v[j]);
                    break;
                }
            }
            if(j == n)
                P[cnt] = 0, Q[cnt] = 0;
            // do the swappings
            // look for first element not correct in go
        }
        if(sorted())
            return cnt;
    }
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:53:1: warning: control reaches end of non-void function [-Wreturn-type]
   53 | }
      | ^
sorting.cpp: In lambda function:
sorting.cpp:28:9: warning: control reaches end of non-void function [-Wreturn-type]
   28 |         };
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 304 KB Output is correct
2 Correct 0 ms 296 KB Output is correct
3 Runtime error 1 ms 432 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 304 KB Output is correct
2 Correct 0 ms 296 KB Output is correct
3 Runtime error 1 ms 432 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 340 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 304 KB Output is correct
2 Correct 0 ms 296 KB Output is correct
3 Runtime error 1 ms 432 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1080 ms 412 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1080 ms 412 KB Time limit exceeded
2 Halted 0 ms 0 KB -