Submission #322499

# Submission time Handle Problem Language Result Execution time Memory
322499 2020-11-14T18:46:35 Z JovanK26 Sorting (IOI15_sorting) C++14
20 / 100
2 ms 492 KB
#include <bits/stdc++.h>
#include "sorting.h"
using namespace std;
int sz,l,r,rez,m;
int S1[500005],A[500005];
vector < pair<int,int > > v;
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[])
{
    l=0;
    r=M;
    rez=-1;
    while(l<=r)
    {
        m=(l+r)/2;
        for(int i=0;i<N;i++)
        {
            S1[i]=S[i];
        }
        for(int i=0;i<m;i++)
        {
            swap(S1[X[i]],S1[Y[i]]);
        }
        for(int i=0;i<N;i++)
        {
            A[S1[i]]=i;
        }
        v.clear();
        for(int i=0;i<N;i++)
        {
            if(S1[i]==i)continue;
            v.push_back(make_pair(i,S1[i]));
            swap(S1[i],S1[A[i]]);
            swap(A[i],A[S1[A[i]]]);
        }
        sz=v.size();
        if(sz<=m)
        {
            for(int i=0;i<N;i++)
            {
                S1[i]=S[i];
                A[S1[i]]=i;
            }
            for(int i=0;i<M;i++)
            {
                swap(A[S1[X[i]]],A[S1[Y[i]]]);
                swap(S1[X[i]],S1[Y[i]]);
                if(i<sz)
                {
                    P[i]=A[v[i].first];
                    Q[i]=A[v[i].second];
                    swap(A[v[i].first],A[v[i].second]);
                    swap(S1[A[P[i]]],S1[A[Q[i]]]);
                }
                else
                {
                    P[i]=0;
                    Q[i]=0;
                }
            }
            r=m-1;
            rez=m;
        }
        else
        {
            l=m+1;
        }
    }
    return rez;
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:35:18: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   35 |         sz=v.size();
      |            ~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Incorrect 1 ms 364 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -