답안 #288736

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
288736 2020-09-01T19:51:09 Z b00n0rp 정렬하기 (IOI15_sorting) C++17
100 / 100
356 ms 17584 KB
#include "sorting.h"

#include<bits/stdc++.h>
using namespace std;

#define pii pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define pb push_back
#define SZ(v) (int)v.size()

const int MAXN = 200005;

int a[MAXN],b[MAXN];

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    int low = 0,high = M,mid,ans;
    while(low <= high){
    	mid = (low+high)/2;
    	vector<pii> v;

    	for(int i = 0; i < N; i ++) a[i] = S[i];
    	for(int i = 0; i < mid; i ++){
    		swap(a[X[i]],a[Y[i]]);
    	}
    	for(int i = 0; i < N; i ++) b[a[i]] = i;
    	for(int i = 0; i < N; i ++){
    		if(a[i] == i) continue;
    		int pos = b[i];
    		int val = a[i];
    		a[i] = i;
    		a[pos] = val;
    		b[i] = i;
    		b[val] = pos;
    		v.pb({i,val});
    	}

    	while(SZ(v) < mid) v.pb({0,0});

    	if(SZ(v) == mid){
    		ans = mid;
    		high = mid-1;

    		for(int i = 0; i < N; i ++){
    			a[i] = S[i];
    			b[a[i]] = i;
    		}

    		for(int i = 0; i < mid; i++){
    			swap(a[X[i]],a[Y[i]]);
    			b[a[X[i]]] = X[i];
    			b[a[Y[i]]] = Y[i];

    			P[i] = b[v[i].F];
    			Q[i] = b[v[i].S];

    			swap(a[P[i]],a[Q[i]]);
    			b[a[P[i]]] = P[i];
    			b[a[Q[i]]] = Q[i];
    		}

    	}
    	else low = mid+1;
    }
    return ans;
}


Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:66:12: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   66 |     return ans;
      |            ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 2 ms 768 KB Output is correct
22 Correct 2 ms 768 KB Output is correct
23 Correct 2 ms 768 KB Output is correct
24 Correct 2 ms 768 KB Output is correct
25 Correct 2 ms 768 KB Output is correct
26 Correct 2 ms 768 KB Output is correct
27 Correct 2 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 237 ms 16056 KB Output is correct
16 Correct 282 ms 16268 KB Output is correct
17 Correct 285 ms 16916 KB Output is correct
18 Correct 121 ms 13556 KB Output is correct
19 Correct 203 ms 15324 KB Output is correct
20 Correct 224 ms 15704 KB Output is correct
21 Correct 198 ms 15788 KB Output is correct
22 Correct 232 ms 17276 KB Output is correct
23 Correct 272 ms 17360 KB Output is correct
24 Correct 321 ms 17260 KB Output is correct
25 Correct 356 ms 16976 KB Output is correct
26 Correct 236 ms 15676 KB Output is correct
27 Correct 217 ms 15220 KB Output is correct
28 Correct 279 ms 17128 KB Output is correct
29 Correct 303 ms 16892 KB Output is correct
30 Correct 174 ms 14892 KB Output is correct
31 Correct 324 ms 16972 KB Output is correct
32 Correct 261 ms 16916 KB Output is correct
33 Correct 341 ms 17136 KB Output is correct
34 Correct 274 ms 17272 KB Output is correct
35 Correct 205 ms 15116 KB Output is correct
36 Correct 99 ms 14288 KB Output is correct
37 Correct 331 ms 17584 KB Output is correct
38 Correct 315 ms 16968 KB Output is correct
39 Correct 317 ms 17148 KB Output is correct