답안 #387232

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
387232 2021-04-08T07:00:32 Z Keshi 정렬하기 (IOI15_sorting) C++17
74 / 100
1000 ms 17060 KB
//In the name of God
#include <bits/stdc++.h>
#include "sorting.h"
using namespace std;

typedef int ll;
typedef pair<ll, ll> pll;

const ll maxn = 2e5 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e9;

#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second
#define Sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()

int g[maxn], a[maxn], b[maxn];
bool vis[maxn];

int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]) {
	for(ll i = 0; i < n; i++){
		a[i] = s[i];
	}
	for(ll j = 0; j <= m; j++){
		for(ll i = 0; i < n; i++){
			g[a[i]] = i;
			vis[i] = 0;
		}
		vector<vector<ll> > vec;
		for(ll i = 0; i < n; i++){
			if(vis[i]) continue;
			vector<ll> v2;
			ll v = i;
			do{
				vis[v] = 1;
				v2.pb(v);
				v = g[v];
			}while(v != i);
			vec.pb(v2);
		}
		if(j >= n - Sz(vec)){
			// inja oke
			vector<ll> v2(10);
			vec.pb(v2);
			ll p1 = 0;
			ll p2 = 1;
			for(ll i = 0; i < n; i++){
				b[s[i]] = i;
			}
			for(ll o = 0; o < j; o++){
				cout.flush();
				swap(s[x[o]], s[y[o]]);
				swap(b[s[x[o]]], b[s[y[o]]]);
				while(p2 == Sz(vec[p1])){
					p1++;
					p2 = 1;
				}
				p[o] = b[vec[p1][0]];
				q[o] = b[vec[p1][p2]];
				p2++;
				swap(s[p[o]], s[q[o]]);
				swap(b[s[p[o]]], b[s[q[o]]]);
			}
			return j;
		}
		if(j != m) swap(a[x[j]], a[y[j]]);
	}
	cout << 1 / 0;
	return -1;
}


/*int main(){
    fast_io;



    return 0;
}*/

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:73:12: warning: division by zero [-Wdiv-by-zero]
   73 |  cout << 1 / 0;
      |          ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 4 ms 620 KB Output is correct
22 Correct 4 ms 620 KB Output is correct
23 Correct 5 ms 764 KB Output is correct
24 Correct 10 ms 620 KB Output is correct
25 Correct 7 ms 640 KB Output is correct
26 Correct 12 ms 620 KB Output is correct
27 Correct 15 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 492 KB Output is correct
2 Correct 36 ms 620 KB Output is correct
3 Correct 34 ms 620 KB Output is correct
4 Correct 2 ms 620 KB Output is correct
5 Correct 23 ms 620 KB Output is correct
6 Correct 59 ms 620 KB Output is correct
7 Correct 159 ms 620 KB Output is correct
8 Correct 35 ms 620 KB Output is correct
9 Correct 37 ms 620 KB Output is correct
10 Correct 38 ms 748 KB Output is correct
11 Correct 114 ms 620 KB Output is correct
12 Correct 161 ms 620 KB Output is correct
13 Correct 219 ms 748 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 492 KB Output is correct
2 Correct 36 ms 620 KB Output is correct
3 Correct 34 ms 620 KB Output is correct
4 Correct 2 ms 620 KB Output is correct
5 Correct 23 ms 620 KB Output is correct
6 Correct 59 ms 620 KB Output is correct
7 Correct 159 ms 620 KB Output is correct
8 Correct 35 ms 620 KB Output is correct
9 Correct 37 ms 620 KB Output is correct
10 Correct 38 ms 748 KB Output is correct
11 Correct 114 ms 620 KB Output is correct
12 Correct 161 ms 620 KB Output is correct
13 Correct 219 ms 748 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Execution timed out 1093 ms 17060 KB Time limit exceeded
16 Halted 0 ms 0 KB -