Submission #1081952

# Submission time Handle Problem Language Result Execution time Memory
1081952 2024-08-30T13:13:48 Z Trumling Sorting (IOI15_sorting) C++14
0 / 100
2 ms 1884 KB
#include "sorting.h"
#include<bits/stdc++.h>
using namespace std;
     
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(),x.end()
#define INF 9999999999999999
typedef long long ll;
ll n;
 
 int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) 
{ 
	n=N;
    ll pos[N];
    for(int i=0;i<N;i++)
		pos[S[i]]=i;
	
	vector<deque<pair<ll,pair<ll,ll>>>>v(n);
	for(int i=0;i<M;i++)
		v[Y[i]].pb({X[i],{v[X[i]].size()-1,i}});
 
	vector<pair<ll,ll>>vi;
	for(int i=0;i<M;i++)
	{
		pos[S[X[i]]]=Y[i];
		pos[S[Y[i]]]=X[i];
		swap(S[X[i]],S[Y[i]]);
 
		if(i<N)
		{
			ll posi=i;
			ll idx=v[i].size()-1;
			ll ii=((v[i].size())?v[i][v[i].size()-1].S.S:-1);
			while(ii>i)
			{
				ll posi2=v[posi][idx].F;
				ll idx2=v[posi][idx].S.F;
				ll ii2=v[posi][idx].S.S;
 
				if(ii2<=i)
					break;
				
				posi=posi2;
				idx=idx2;
				ii2=ii;
				if(idx<0)
					break;
			}
 
          if(posi!=pos[i])
            vi.pb({posi,pos[i]});
          
 
			swap(S[posi],S[pos[i]]);
			pos[S[pos[i]]]=pos[i];
			pos[i]=posi;
			
		}
		else
		{
			vi.pb({0,0});
		}
	}
   
   for(int i=0;i<vi.size();i++)
   {
     P[i]=vi[i].F;
     Q[i]=vi[i].S;
   }
 
	return vi.size();
		
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:67:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |    for(int i=0;i<vi.size();i++)
      |                ~^~~~~~~~~~
sorting.cpp:5:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
    5 | #define F first
sorting.cpp:69:17: note: in expansion of macro 'F'
   69 |      P[i]=vi[i].F;
      |                 ^
sorting.cpp:6:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
    6 | #define S second
sorting.cpp:70:17: note: in expansion of macro 'S'
   70 |      Q[i]=vi[i].S;
      |                 ^
sorting.cpp:73:16: warning: conversion from 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   73 |  return vi.size();
      |         ~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 440 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 440 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 440 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1884 KB Output isn't correct
2 Halted 0 ms 0 KB -