답안 #1080904

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1080904 2024-08-29T15:52:28 Z Trumling 정렬하기 (IOI15_sorting) C++14
0 / 100
1 ms 604 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;
	for(int i=0;i<M;i++)
		v[Y[i]].pb({X[i],{v[X[i]].size()-1,i}});

	
	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;
			}

			P[i]=posi;
			Q[i]=pos[i];

			swap(S[posi],S[pos[i]]);
			pos[S[pos[i]]]=pos[i];
			pos[i]=posi;
			
		}
		else
		{
			P[i]=0;
			Q[i]=0;
		}
	}

	return M;
		
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:52:9: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   52 |    P[i]=posi;
      |         ^~~~
sorting.cpp:53:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   53 |    Q[i]=pos[i];
      |         ~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -