답안 #1053712

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1053712 2024-08-11T16:06:28 Z XJP12 정렬하기 (IOI15_sorting) C++14
0 / 100
1 ms 440 KB
#include <bits/stdc++.h>
#include "sorting.h"
using namespace std;
typedef vector<int> vi;
int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]) {
	int r=0;
	bool ban=true;
	for(int i=0; i<n; i++){
		if(s[i]!=i){
			ban=false;
			break;
		}
	}
	if (ban) return 0;
    if(y[0]==1){
		for(int i=0; i<n; i++){
			swap(s[1], s[0]);
			r++;
			/*for(int j=0; j<n; j++){
				cout<<s[j]<<" ";
			}*/
		//	cout<<endl;
		ban=true;
		for(int j=0; j<n; j++){
			if(s[j]!=j){
				ban=false;
				break;
			}
		}
		if (ban) break;
			for(int j=0; j<n; j++){
				if(s[j]==i){
					if(s[i]==0 && i==1){
						p[i]=j;
						q[i]=i-1;
						swap(s[i-1], s[j]);
					}else{
					p[i]=j;
					q[i]=i;
					swap(s[i], s[j]);
					}
					break;
				}
			}
		/*	for(int j=0; j<n; j++){
				cout<<s[j]<<" ";
			}
			cout<<endl<<endl;*/
		}
		if(s[1]!=1 && s[0]!=0){
			p[r]=0;
			q[r]=1;
			r++;
		}
			/*for(int i=0; i<r; i++){
			cout<<p[i]<<" "<<q[i]<<endl;
		}*/
	}else{
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				if(s[j]==i && j!=i){
					r++;
					p[i]=j;
					q[i]=i;
					swap(s[i], s[j]);
					break;
				}
			}
		/*	for(int j=0; j<n; j++){
				cout<<s[j]<<" ";
			}
			cout<<endl;*/
		}
	/*	for(int i=0; i<r; i++){
			cout<<p[i]<<" "<<q[i]<<endl;
		}*/
	}
	return r;
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:5:39: warning: unused parameter 'm' [-Wunused-parameter]
    5 | int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]) {
      |                                   ~~~~^
sorting.cpp:5:46: warning: unused parameter 'x' [-Wunused-parameter]
    5 | int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]) {
      |                                          ~~~~^~~
# 결과 실행 시간 메모리 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 440 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -