Submission #1108062

# Submission time Handle Problem Language Result Execution time Memory
1108062 2024-11-02T16:11:24 Z Aviansh Sorting (IOI15_sorting) C++17
0 / 100
89 ms 77640 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 be[n];
    int tp[n];
    copy(s,s+n,tp);
    iota(be,be+n,0);
    int ber[m][n];
    for(int i = m-1;i>=0;i--){
        swap(be[x[i]],be[y[i]]);
        for(int j = 0;j<n;j++){
            ber[i][be[j]]=j;
        }
    }
    int r = 0;
    for(int i = 0;i<n;i++){
        swap(s[x[i]],s[y[i]]);
        int ind = find(s,s+n,i)-s;
        swap(s[ind],s[ber[r+1][i]]);
        assert(ber[r+1][i]==i);
        p[r]=ind;
        q[r]=(ber[r+1][i]);
        r++;
    }
    assert(r<=m);
    for(;r<m;r++){
        p[r]=0;
        q[r]=0;
        swap(s[x[r]],s[y[r]]);
    }
    for(int i = 0;i<r;i++){
        swap(tp[p[i]],tp[q[i]]);
    }
    for(int i = 0;i<n;i++){
        assert(tp[i]==i);
    }
	return r;
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:21:32: warning: conversion from 'long int' to 'int' may change value [-Wconversion]
   21 |         int ind = find(s,s+n,i)-s;
      |                   ~~~~~~~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Incorrect 1 ms 336 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Incorrect 1 ms 336 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 336 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Incorrect 1 ms 336 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 89 ms 77640 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 89 ms 77640 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -