답안 #590870

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
590870 2022-07-06T12:32:08 Z FatihSolak 정렬하기 (IOI15_sorting) C++17
54 / 100
3 ms 596 KB
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]) {
	if(is_sorted(s,s+n))
		return 0;
	for(int i = 0;i<m;i++){
		p[i] = q[i] = 0;
	}
	vector<int> fnal;
	vector<int> now;
	vector<int> pfnal(n,0);
	vector<int> pnow(n,0);
	int cnt = 0;
	for(int i = 0;i<n;i++){
		fnal.push_back(s[i]);
		pfnal[s[i]] = i;
		now.push_back(s[i]);
		pnow[s[i]] = i;
		cnt += (s[i] == i);
	}
	for(int i = 0;i<m;i++){
		swap(pfnal[fnal[x[i]]],pfnal[fnal[y[i]]]);
		swap(fnal[x[i]],fnal[y[i]]);
	}
	for(int i = 0;i<m;i++){
		if(pnow[now[x[i]]] == now[x[i]])cnt--;
		if(pnow[now[y[i]]] == now[y[i]])cnt--;
		swap(now[x[i]],now[y[i]]);
		swap(pnow[now[x[i]]],pnow[now[y[i]]]);
		if(pnow[now[x[i]]] == now[x[i]])cnt++;
		if(pnow[now[y[i]]] == now[y[i]])cnt++;
		if(i < n){
			int ps1 = pnow[i];
			int ps2 = pnow[fnal[i]];
			p[i] = ps1;
			q[i] = ps2;
			if(pnow[now[ps1]] == now[ps1])cnt--;
			if(pnow[now[ps2]] == now[ps2])cnt--;
			swap(pnow[now[ps1]],pnow[now[ps2]]);
			swap(now[ps1],now[ps2]);
			if(pnow[now[ps1]] == now[ps1])cnt++;
			if(pnow[now[ps2]] == now[ps2])cnt++;
			int tmp = pfnal[i];
			swap(pfnal[fnal[i]],pfnal[i]);
			swap(fnal[i],fnal[tmp]);
		}
		if(cnt == n)
			return i+1;
	}
	assert(0);
}


# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 3 ms 468 KB Output is correct
22 Correct 3 ms 468 KB Output is correct
23 Correct 3 ms 552 KB Output is correct
24 Correct 3 ms 468 KB Output is correct
25 Correct 3 ms 596 KB Output is correct
26 Correct 3 ms 468 KB Output is correct
27 Correct 3 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -