답안 #320716

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
320716 2020-11-09T15:28:40 Z knon0501 정렬하기 (IOI15_sorting) C++14
100 / 100
495 ms 25060 KB
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
const int MX=2e5+5;
int a[MX];
int b[MX];
int c[MX];
int d[MX];
int dd[MX];
int e[MX];
int p[MX];
int q[MX];
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    P[0] = 0;
	Q[0] = 0;
	int i,j,k;

	int ret=N;
	int lef=0;
	int rig=N-1;

	while(rig>=lef){
        int mid=(lef+rig)/2;
        for(i=0 ; i<N ; i++){
            a[i]=b[i]=S[i];
            e[a[i]]=i;
        }
        for(i=0  ; i<mid ; i++){
            p[i]=q[i]=0;
            swap(b[X[i]],b[Y[i]]);
        }
        for(i=0 ; i<N ; i++)
            c[b[i]]=i;
        for(i=0 ; i<N ; i++)
            d[i]=c[a[i]],dd[d[i]]=i;
        int j=0;
        for(i=0 ; i<mid ; i++){
            swap(dd[d[X[i]]],dd[d[Y[i]]]);
            swap(e[a[X[i]]],e[a[Y[i]]]);

            swap(d[X[i]],d[Y[i]]);
            swap(a[X[i]],a[Y[i]]);
            while(j<N && e[j]==dd[j]){
                j++;

            }
            if(j<N){
                int k=a[dd[j]];
                p[i]=e[j];
                q[i]=dd[j];
                swap(a[e[j]],a[dd[j]]);
                swap(e[j],e[k]);

            }
        }
        int isok=1;
        for(i=0 ; i<N ; i++){
   
            if(i!=a[i])isok=0;
        }
    
        if(isok==1){
            rig=mid-1;
            ret=mid;
            for(i=0 ; i<mid ; i++)
            {
                P[i]=p[i];
                Q[i]=q[i];
            }
        }
        else
            lef=mid+1;
	}


	return ret;
}


Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:36:13: warning: declaration of 'j' shadows a previous local [-Wshadow]
   36 |         int j=0;
      |             ^
sorting.cpp:16:8: note: shadowed declaration is here
   16 |  int i,j,k;
      |        ^
sorting.cpp:48:21: warning: declaration of 'k' shadows a previous local [-Wshadow]
   48 |                 int k=a[dd[j]];
      |                     ^
sorting.cpp:16:10: note: shadowed declaration is here
   16 |  int i,j,k;
      |          ^
sorting.cpp:16:8: warning: unused variable 'j' [-Wunused-variable]
   16 |  int i,j,k;
      |        ^
sorting.cpp:16:10: warning: unused variable 'k' [-Wunused-variable]
   16 |  int i,j,k;
      |          ^
sorting.cpp:13:39: warning: unused parameter 'M' [-Wunused-parameter]
   13 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                   ~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 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 0 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 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 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 0 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 492 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 620 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 492 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 620 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 271 ms 22116 KB Output is correct
16 Correct 316 ms 22628 KB Output is correct
17 Correct 449 ms 23856 KB Output is correct
18 Correct 107 ms 19300 KB Output is correct
19 Correct 257 ms 21604 KB Output is correct
20 Correct 284 ms 23040 KB Output is correct
21 Correct 308 ms 23140 KB Output is correct
22 Correct 259 ms 19300 KB Output is correct
23 Correct 253 ms 24804 KB Output is correct
24 Correct 495 ms 24420 KB Output is correct
25 Correct 476 ms 24164 KB Output is correct
26 Correct 318 ms 22244 KB Output is correct
27 Correct 290 ms 21604 KB Output is correct
28 Correct 410 ms 24424 KB Output is correct
29 Correct 397 ms 23524 KB Output is correct
30 Correct 228 ms 21348 KB Output is correct
31 Correct 452 ms 24036 KB Output is correct
32 Correct 298 ms 23908 KB Output is correct
33 Correct 472 ms 24420 KB Output is correct
34 Correct 343 ms 24292 KB Output is correct
35 Correct 265 ms 21348 KB Output is correct
36 Correct 96 ms 20580 KB Output is correct
37 Correct 413 ms 25060 KB Output is correct
38 Correct 394 ms 24312 KB Output is correct
39 Correct 384 ms 24164 KB Output is correct