답안 #1098428

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1098428 2024-10-09T11:33:47 Z alexander707070 정렬하기 (IOI15_sorting) C++14
54 / 100
1000 ms 680 KB
#include<bits/stdc++.h>
#include "sorting.h"

#define MAXN 200007
using namespace std;

int n,m,q;
int pos[MAXN],s[MAXN];

int to[MAXN];

bool check(){
	for(int i=0;i<n-1;i++){
		if(s[i]>s[i+1])return false;
	}

	return true;
}

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    n=N; m=M;


	for(int stop=0;stop<n;stop++){

		for(int i=0;i<n;i++)s[i]=i;
		for(int i=0;i<stop;i++)swap(s[X[i]],s[Y[i]]);

		for(int i=0;i<n;i++)to[s[i]]=i;
		for(int i=0;i<n;i++)s[i]=S[i];

		for(int i=0;i<stop;i++){
			P[i]=Q[i]=0;

			swap(s[X[i]],s[Y[i]]);
			swap(to[X[i]],to[Y[i]]);

			for(int f=0;f<n;f++){
				if(to[f]!=s[f]){
					for(int k=0;k<n;k++){
						if(s[k]==to[f]){

							P[i]=f; Q[i]=k;
							swap(s[k],s[f]);
						}
					}
					break;
				}
			}
		}

		q=stop;
		for(int i=0;i<n;i++)s[i]=S[i];

		for(int i=0;i<n;i++){
			if(check())return i;

			swap(s[X[i]],s[Y[i]]);
			swap(s[P[i]],s[Q[i]]);
		}

		if(check())return q;
	}
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:64:1: warning: control reaches end of non-void function [-Wreturn-type]
   64 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 440 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 444 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 440 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 444 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 448 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 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 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 440 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 444 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 448 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 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 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 452 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 53 ms 656 KB Output is correct
22 Correct 46 ms 604 KB Output is correct
23 Correct 51 ms 680 KB Output is correct
24 Correct 36 ms 600 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 16 ms 572 KB Output is correct
27 Correct 50 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1078 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1078 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -