답안 #422727

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
422727 2021-06-10T11:15:40 Z vanic 정렬하기 (IOI15_sorting) C++14
0 / 100
1 ms 588 KB
#include "sorting.h"
#include <algorithm>
#include <iostream>
#include <cassert>

using namespace std;

const int maxn=2e5+5;

int pos[maxn];

int findSwapPairs(int n, int l[], int m, int x[], int y[], int p[], int q[]){
	for(int i=0; i<n; i++){
		pos[l[i]]=i;
	}
	int br=2;
	for(int i=0; i<n-2; i++){
		swap(l[x[i]], l[y[i]]);
		swap(pos[l[x[i]]], pos[l[y[i]]]);
		p[i]=min(pos[br], br);
		q[i]=max(pos[br], br);
		swap(l[p[i]], l[q[i]]);
		swap(pos[l[p[i]]], pos[l[q[i]]]);
		br++;
	}
	int sol;
	if(l[0]==0){
		sol=n-2;
	}
	else{
		sol=n-1;
		swap(l[x[n-2]], l[y[n-2]]);
		swap(pos[l[x[n-2]]], pos[l[y[n-2]]]);
		p[n-2]=0;
		if(l[0]!=0){
			q[n-2]=1;
		}
		else{
			q[n-2]=0;
		}
		swap(l[p[n-2]], l[q[n-2]]);
		swap(pos[l[p[n-2]]], pos[l[q[n-2]]]);
	}
/*	cout << "krece" << endl;
	for(int i=0; i<sol; i++){
		cout << p[i] << ' ' << q[i] << '\n';
	}*/
	for(int i=0; i<n; i++){
		assert(l[i]==i);
	}
	return sol;
}

/*
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	int s[n];
	for(int i=0; i<n; i++){
		cin >> s[i];
	}
	int m;
	cin >> m;
	int x[m], y[m];
	for(int i=0; i<m; i++){
		cin >> x[i] >> y[i];
	}
	int p[m], q[m];
	cout << findSwapPairs(n, s, m, x, y, p, q) << endl;
	return 0;
}
*/

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:12:39: warning: unused parameter 'm' [-Wunused-parameter]
   12 | int findSwapPairs(int n, int l[], int m, int x[], int y[], int p[], int q[]){
      |                                   ~~~~^
# 결과 실행 시간 메모리 Grader output
1 Failed 1 ms 204 KB MODEL SOLUTION IS WRONG
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 1 ms 204 KB MODEL SOLUTION IS WRONG
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Failed 1 ms 204 KB MODEL SOLUTION IS WRONG
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 588 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 588 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -