제출 #1235898

#제출 시각아이디문제언어결과실행 시간메모리
1235898kl0989e정렬하기 (IOI15_sorting)C++20
0 / 100
1 ms328 KiB
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pi pair<int, int>
#define pl pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()

bool check(int n, int s[], int r, int x[], int y[], int p[], int q[]) {
	for (int i=0; i<r; i++) {
		swap(s[x[i]],s[y[i]]);
		swap(s[p[i]],s[q[i]]);
	}
	bool ok=1;
	for (int i=0; i<n; i++) {
		ok&=(s[i]==i);
	}
	return ok;
}

int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]) {
	int ss[n];
	for (int i=0; i<n; i++) {
		ss[i]=s[i];
	}
    vi loc(n);
	for (int i=0; i<n; i++) {
		loc[s[i]]=i;
	}
	for (int i=0; i<n-1; i++) {
		p[i]=loc[i];
		q[i]=i;
		swap(loc[i],loc[s[i]]);
		swap(s[i],s[loc[s[i]]]);
	}
	for (int i=0; i<n; i++) {
		s[i]=ss[i];
	}
	assert(check(n,ss,n-1,x,y,p,q));
	return n-1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...