답안 #868120

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
868120 2023-10-30T12:59:47 Z waldi 정렬하기 (IOI15_sorting) C++17
74 / 100
1000 ms 20372 KB
#include "sorting.h"
#include <bits/stdc++.h>
#define FOR(i,p,k) for(int i=(p);i<=(k);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define debug(a) cerr << #a << ": " << a << "\n";
#define fi first
#define se second
#define ssize(x) (int(x.size()))
#define all(x) x.begin(),x.end()
using namespace std;
typedef pair<int, int> pii;

int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]){
	auto sprawdz = [&](int wyn){
		vector<int> co_winno(n), gdzie_winno(n);
		REP(i, n) co_winno[i] = gdzie_winno[i] = i;
		for(int i = wyn; ~--i;){
			int a = x[i], b = y[i];
			swap(co_winno[a], co_winno[b]);
			swap(gdzie_winno[co_winno[a]], gdzie_winno[co_winno[b]]);
		}
		
		vector<int> co_jest(n), gdzie_jest(n);
		REP(i, n) co_jest[i] = s[i], gdzie_jest[s[i]] = i;
		
		vector<int> graf(n);// [wartosc teraz] = wartosc na koncu
		REP(i, n) graf[i] = co_winno[gdzie_jest[i]];
		
		vector<bool> odw(n, 0);
		vector<pii> zmiany_wart;
		REP(i, n) if(!odw[i]){
			for(int w = i; !odw[w]; w = graf[w]) odw[w] = 1, zmiany_wart.emplace_back(w, graf[w]);
			zmiany_wart.pop_back();
		}
		if(ssize(zmiany_wart) > wyn) return 0;
		while(ssize(zmiany_wart) < wyn) zmiany_wart.emplace_back(0, 0);
		reverse(all(zmiany_wart));
		
		REP(i, wyn){
			swap(co_jest[x[i]], co_jest[y[i]]);
			swap(gdzie_jest[co_jest[x[i]]], gdzie_jest[co_jest[y[i]]]);
			
			int w1 = zmiany_wart[i].fi, w2 = zmiany_wart[i].se;
			int poz1 = gdzie_jest[w1], poz2 = gdzie_jest[w2];
			p[i] = poz1, q[i] = poz2;
			swap(gdzie_jest[w1], gdzie_jest[w2]);
			swap(co_jest[poz1], co_jest[poz2]);
		}
		return 1;
	};
	
	int wyn = -1;
	FOR(i, 0, m){
		if(sprawdz(i)){wyn = i; break;}
	}
	/*for(int lewo = 0, prawo = m; lewo <= prawo;){
		int sr = (lewo+prawo)>>1;
		if(sprawdz(sr)) wyn = sr, prawo = sr-1;
		else lewo = sr+1;
	}*/
	return wyn;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 432 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 432 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 432 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 3 ms 600 KB Output is correct
22 Correct 3 ms 600 KB Output is correct
23 Correct 3 ms 604 KB Output is correct
24 Correct 3 ms 604 KB Output is correct
25 Correct 1 ms 564 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 3 ms 680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 604 KB Output is correct
2 Correct 32 ms 600 KB Output is correct
3 Correct 28 ms 608 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 5 ms 604 KB Output is correct
7 Correct 15 ms 604 KB Output is correct
8 Correct 30 ms 444 KB Output is correct
9 Correct 30 ms 856 KB Output is correct
10 Correct 31 ms 616 KB Output is correct
11 Correct 26 ms 600 KB Output is correct
12 Correct 15 ms 604 KB Output is correct
13 Correct 29 ms 600 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 604 KB Output is correct
2 Correct 32 ms 600 KB Output is correct
3 Correct 28 ms 608 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 5 ms 604 KB Output is correct
7 Correct 15 ms 604 KB Output is correct
8 Correct 30 ms 444 KB Output is correct
9 Correct 30 ms 856 KB Output is correct
10 Correct 31 ms 616 KB Output is correct
11 Correct 26 ms 600 KB Output is correct
12 Correct 15 ms 604 KB Output is correct
13 Correct 29 ms 600 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Execution timed out 1090 ms 20372 KB Time limit exceeded
16 Halted 0 ms 0 KB -