답안 #314921

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
314921 2020-10-21T16:11:49 Z tengiz05 정렬하기 (IOI15_sorting) C++17
0 / 100
2 ms 512 KB
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
int n, m;
int x[N], y[N], pos[N], a[N], orig[N];
vector<pair<int, int>> v, v1;
bool check(int mid){
	v.clear();v1.clear();
	for(int i=0;i<mid;i++){
		swap(a[x[i]], a[y[i]]);
	}for(int i=0;i<n;i++)pos[a[i]] = i;
	int ans = 0;
	for(int i=0;i<n;i++){
		if(pos[i] == i){
			continue;
		}else {
			ans++;
			int f = i, s = pos[i];
			pos[a[i]] = s;
			swap(pos[f], pos[s]);
			swap(a[f], a[s]);
			v1.push_back({f, s});
		}
	}
	if(ans > mid)return 0;
	int j=0;
	for(int i=0;i<n;i++)a[i] = orig[i], pos[orig[i]] = i;
	for(int i=0;i<mid;i++){
		if(j > v1.size())v.push_back({0,0});
		else {
			swap(pos[a[x[i]]], pos[a[y[i]]]);
			swap(a[x[i]], a[y[i]]);
			v.push_back({pos[v1[j].first], pos[v1[j].second]});
		}j++;
	}return 1;
}
int findSwapPairs(int NN, int A[], int MM, int X[], int Y[], int P[], int Q[]) {
	n = NN, m = MM;
	int l = 0, r = m;
	for(int i=0;i<m;i++){
		x[i] = X[i];
		y[i] = Y[i];
	}
	while(l+1 < r){
		for(int i=0;i<n;i++)a[i] = A[i], orig[i] = A[i];
		int mid = (l+r)/2;
		if(check(mid)){
			r = mid;
		}else {
			l = mid;
		}
	}for(int i=0;i<n;i++)a[i] = A[i];
	check(r);
	for(int i=0;i<r;i++){
		if(i < v.size()){
			P[i] = v[i].first;
			Q[i] = v[i].second;
		}else {
			P[i] = Q[i] = 0;
		}
	}
	return r;
}

Compilation message

sorting.cpp: In function 'bool check(int)':
sorting.cpp:30:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |   if(j > v1.size())v.push_back({0,0});
      |      ~~^~~~~~~~~~~
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:56:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   if(i < v.size()){
      |      ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -