Submission #322500

# Submission time Handle Problem Language Result Execution time Memory
322500 2020-11-14T18:47:38 Z JovanK26 Sorting (IOI15_sorting) C++14
100 / 100
390 ms 25216 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[v[i].first]],S1[A[v[i].second]]);
                }
                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 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 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 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 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 364 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 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 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 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 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 364 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 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 3 ms 620 KB Output is correct
22 Correct 3 ms 620 KB Output is correct
23 Correct 3 ms 748 KB Output is correct
24 Correct 3 ms 620 KB Output is correct
25 Correct 3 ms 748 KB Output is correct
26 Correct 3 ms 620 KB Output is correct
27 Correct 3 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 492 KB Output is correct
2 Correct 2 ms 620 KB Output is correct
3 Correct 3 ms 620 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 620 KB Output is correct
8 Correct 3 ms 620 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 492 KB Output is correct
2 Correct 2 ms 620 KB Output is correct
3 Correct 3 ms 620 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 620 KB Output is correct
8 Correct 3 ms 620 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 221 ms 22236 KB Output is correct
16 Correct 273 ms 22720 KB Output is correct
17 Correct 288 ms 24028 KB Output is correct
18 Correct 348 ms 20700 KB Output is correct
19 Correct 287 ms 23232 KB Output is correct
20 Correct 280 ms 23772 KB Output is correct
21 Correct 234 ms 23900 KB Output is correct
22 Correct 214 ms 19420 KB Output is correct
23 Correct 254 ms 24924 KB Output is correct
24 Correct 344 ms 24540 KB Output is correct
25 Correct 390 ms 24168 KB Output is correct
26 Correct 309 ms 23368 KB Output is correct
27 Correct 286 ms 22624 KB Output is correct
28 Correct 317 ms 24284 KB Output is correct
29 Correct 314 ms 23784 KB Output is correct
30 Correct 280 ms 21932 KB Output is correct
31 Correct 375 ms 24344 KB Output is correct
32 Correct 254 ms 24060 KB Output is correct
33 Correct 367 ms 24540 KB Output is correct
34 Correct 284 ms 24580 KB Output is correct
35 Correct 278 ms 22792 KB Output is correct
36 Correct 174 ms 20664 KB Output is correct
37 Correct 354 ms 25216 KB Output is correct
38 Correct 351 ms 24172 KB Output is correct
39 Correct 334 ms 24540 KB Output is correct