Submission #56239

# Submission time Handle Problem Language Result Execution time Memory
56239 2018-07-10T14:20:14 Z aquablitz11 Sorting (IOI15_sorting) C++14
0 / 100
4 ms 512 KB
#include <bits/stdc++.h>
#include "sorting.h"
using namespace std;

const int MAX = 200010; 

using pii = pair<int, int>;
#define F first
#define S second

int n, m;
int *A, *X, *Y, B[MAX];
bool vis[MAX];

vector<pii> check(int len)
{
    for (int i = 0; i < n; ++i)
        B[i] = A[i], vis[i] = false;
    for (int i = 0; i < len; ++i)
        swap(B[X[i]], B[Y[i]]);
    vector<pii> ans;
    for (int s = 0; s < n; ++s) {
        if (vis[s]) continue;
        int u = s;
        while (true) {
            vis[u] = true;
            int v = B[u];
            if (!vis[v])
                ans.push_back({u, v});
            else
                break;
            u = v;
        }
    }
    return ans;
}

int findSwapPairs(int N, int S[], int M, int BX[], int BY[], int P[], int Q[])
{
    n = N, m = M;
    A = S, X = BX, Y = BY;

    int b = 0;
    int e = m;
    while (b < e) {
        int x = (b+e)/2;
        if (check(x).size() <= x)
            e = x;
        else
            b = x+1;
    }
    vector<pii> way = check(b);
    for (int i = 0; i < n; ++i)
        B[A[i]] = i;
    for (int i = 0; i < way.size(); ++i) {
        swap(B[A[X[i]]], B[A[Y[i]]]);
        swap(A[X[i]], A[Y[i]]);
        int x = way[way.size()-i-1].F, y = way[way.size()-i-1].S;
        P[i] = B[x], Q[i] = B[y];
        swap(A[B[x]], A[B[y]]);
        swap(B[x], B[y]);
    }

    return b;
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:47:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (check(x).size() <= x)
             ~~~~~~~~~~~~~~~~^~~~
sorting.cpp:55:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < way.size(); ++i) {
                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Incorrect 3 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Incorrect 3 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Incorrect 3 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -