Submission #287383

# Submission time Handle Problem Language Result Execution time Memory
287383 2020-08-31T16:35:00 Z AaronNaidu Sorting (IOI15_sorting) C++14
0 / 100
2 ms 512 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> s;
int n;
int p[100000];
int q[100000];

void finish(int x) {
    //cout << "Takes " << x << "\n";
    for (int i = 0; i < x; i++)
    {
        //cout << "Round " << i << ": swap " << p[i] << " and " << q[i] << "\n";
    }
    return;
}

bool sorted() {
    for (int i = 0; i < n; i++)
    {
        if (s[i] != i)
        {
            return false;
        }
    }
    return true;
}

int findSwapPairs(int N,int S[],int M, int X[],int Y[],int P[],int Q[]) {
    n = N;
    for (int i = 0; i < N; i++)
    {
        s.push_back(S[i]);
    }
    for (int i = N-1; i >= 0; i--)
    {
        if (sorted())
        {
           // finish(N-1-i);
            return N-1-i;
        }
        swap(s[X[N-1-i]], s[Y[N-1-i]]);
       // cout << "He swaps " << X[N-1-i] << " and " << Y[N-1-i] << "\n";
       // cout << "Sequence is now: ";
        //for (int k = 0; k < n; k++)
        //{
           // cout << s[k] << " ";
       // }
       // cout << "\n";
        for (int j = 0; j < N; j++)
        {
            if (s[j] == i)
            {
                P[N-1-i] = j;
                p[N-1-i] = j;
                Q[N-1-i] = i;
                q[N-1-i] = i;
                swap(s[j], s[i]);
                //cout << "We swap " << j << " and " << i << "\n";
                //cout << "Sequence is now: ";
                //for (int k = 0; k < n; k++)
                //{
                   // cout << s[k] << " ";
                //}
               // cout << "\n";
                break;
            }
        }
    }
    //finish(N);
    return N;
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:29:37: warning: unused parameter 'M' [-Wunused-parameter]
   29 | int findSwapPairs(int N,int S[],int M, int X[],int Y[],int P[],int Q[]) {
      |                                 ~~~~^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Incorrect 1 ms 256 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Incorrect 1 ms 256 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Incorrect 1 ms 256 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -