Submission #160748

# Submission time Handle Problem Language Result Execution time Memory
160748 2019-10-29T18:28:26 Z davitmarg Sorting (IOI15_sorting) C++17
0 / 100
28 ms 504 KB
/*DavitMarg*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <list>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;
#ifndef death
	#include "sorting.h"
#endif

const int N = 200005;

int n,q,x[3*N],y[3*N];
vector<int> s,pos;

vector<pair<int,int>> solve(int r)
{
    vector<int> a=s,p=s;
    vector<pair<int,int>> ans;

    for(int i=0;i<r;i++)
        swap(a[x[i]],a[y[i]]);
    for(int i=0;i<n;i++)
		p[i]=pos[a[i]];
	a=s;

    for(int i=0;i<n;i++)
	{
		//cout<<p[i]<<" ,";
		if(i!=p[a[i]])
		{
            int c,d;
            ans.PB(MP(p[a[i]],i));
            swap(a[p[a[i]]],a[i]);
		}
	}
	return ans;
}

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.PB(S[i]);
	pos=s;
	for(int i=0;i<n;i++)
		pos[s[i]]=i;
	q=M;
	for(int i=0;i<q;i++)
	{
		x[i]=X[i];
		y[i]=Y[i];
	}
	for(int i=1;i<=q;i++)
	{
		vector<pair<int,int>> ans=solve(i);
        if(ans.size()<=i)
		{
			while(ans.size()<i)
				ans.PB(MP(0,0));
            for(int j=0;j<ans.size();j++)
			{
				P[j]=ans[j].first;
				Q[j]=ans[j].second;
			}
			return i;
		}
	}
	return -1;
}


#ifdef death

int main()
{
    int N,S[102],M,X[102],Y[102],P[102],Q[102],R;
    cin>>N;
    for(int i=0;i<N;i++)
		cin>>S[i];
	cin>>M;
    for(int i=0;i<M;i++)
		cin>>X[i]>>Y[i];
	R=findSwapPairs(N,S,M,X,Y,P,Q);
	cout<<R<<endl;
	for(int i=0;i<R;i++)
		cout<<P[i]<<" : "<<Q[i]<<endl;
    return 0;
}

#endif

/*

3
0 2 1
3
0 0
1 1
1 0




5
3 0 4 2 1
5
1 1
4 0
2 3
1 4
0 4

2 0
4 0
4 1
2 3
1 4
0 4

0 1 3 2 4

*/

Compilation message

sorting.cpp: In function 'std::vector<std::pair<int, int> > solve(int)':
sorting.cpp:53:17: warning: unused variable 'c' [-Wunused-variable]
             int c,d;
                 ^
sorting.cpp:53:19: warning: unused variable 'd' [-Wunused-variable]
             int c,d;
                   ^
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:61:70: warning: declaration of 'N' shadows a global declaration [-Wshadow]
 int findSwapPairs(int N,int S[],int M,int X[],int Y[],int P[],int Q[])
                                                                      ^
sorting.cpp:32:11: note: shadowed declaration is here
 const int N = 200005;
           ^
sorting.cpp:78:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(ans.size()<=i)
            ~~~~~~~~~~^~~
sorting.cpp:80:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    while(ans.size()<i)
          ~~~~~~~~~~^~
sorting.cpp:82:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int j=0;j<ans.size();j++)
                         ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -