답안 #790112

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
790112 2023-07-22T10:43:08 Z PoonYaPat 정렬하기 (IOI15_sorting) C++14
0 / 100
1 ms 512 KB
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

int n,m,b[200005],x[200005],y[200005],p[200005],q[200005];
vector<pii> ans;
int a[200005],pos[200005],val[200005],c[200005];

bool check(int h, bool mode) {
	for (int i=0; i<n; ++i) a[i]=i, val[i]=i, c[i]=b[i];
	for (int i=h; i>=0; --i) swap(a[x[i]],a[y[i]]);

	vector<pii> v;
	for (int i=0; i<n; ++i) pos[c[i]]=i;
	for (int i=0; i<n; ++i) {
		if (c[i]!=a[i]) {
			v.push_back(pii(i,pos[a[i]]));
			swap(pos[a[i]],pos[c[i]]);
			swap(c[pos[c[i]]],c[i]);
		}
	}

	if (mode) {
		for (int i=0; i<=h; ++i) {
			swap(val[x[i]],val[y[i]]);
			if (v.size()) {
				ans.push_back(pii(val[v.back().first],val[v.back().second]));
				v.pop_back();
			} else ans.push_back(pii(0,0));
		}
	}

	if (v.size()<=h+1) return true;
	else return false;
}

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
	n=N; m=M;
	for (int i=0; i<n; ++i) b[i]=S[i], x[i]=X[i], y[i]=Y[i];

	int l=0, r=m-1;
	while (l<r) {
		int mid=(l+r)/2;
		if (check(mid,0)) r=mid;
		else l=mid+1;
	}
	check(l,1);

	for (int i=0; i<ans.size(); ++i) P[i]=ans[i].first, Q[i]=ans[i].second;
	return ans.size();
}

Compilation message

sorting.cpp: In function 'bool check(int, bool)':
sorting.cpp:34:14: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |  if (v.size()<=h+1) return true;
      |      ~~~~~~~~^~~~~
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:50:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |  for (int i=0; i<ans.size(); ++i) P[i]=ans[i].first, Q[i]=ans[i].second;
      |                ~^~~~~~~~~~~
sorting.cpp:51:17: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   51 |  return ans.size();
      |         ~~~~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Incorrect 1 ms 316 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Incorrect 1 ms 316 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Incorrect 1 ms 316 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -