답안 #421216

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
421216 2021-06-08T21:38:09 Z Pbezz 정렬하기 (IOI15_sorting) C++14
0 / 100
3 ms 332 KB
#include "sorting.h"
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
typedef pair<ll,ll> pii;

const ll MAXN=2e5+5;
const ll INF=1e9+7;



int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
	int i,k,j,R=0;
	if(N==1)return 0;
	bool ok=true;

	for(i=0;i<N;i++){
	if(S[i]!=i)ok=false;
	}

	if(ok)return 0;

if(Y[0]==1){cout<<"haha1";
swap(S[0],S[1]);

	ok=true;
	for(j=0;j<N;j++){
	if(S[j]!=j)ok=false;
	}
	if(ok)return 1;


for(k=0;k<N;k++){
if(S[k]==0)break;
}

P[R]=k;
Q[R]=1;
R++;
swap(S[k],S[1]);

	ok=true;
	for(j=0;j<N;j++){
	if(S[j]!=j)ok=false;
	}
	if(ok)return 1;

swap(S[0],S[1]);
//agora, 1 esta em posiçao e vamos meter o 2
	ok=true;
	for(j=0;j<N;j++){
	if(S[j]!=j)ok=false;
	}
	if(ok)return 2;


for(k=0;k<N;k++){
if(S[k]==1)break;
}

P[R]=k;
Q[R]=1;
R++;
swap(S[k],S[1]);
//esta tudo bem, continuar
	ok=true;
	for(j=0;j<N;j++){
	if(S[j]!=j)ok=false;
	}
	if(ok)return 2;


for(i=3;i<=N;i++){//find i, send it to ith position

for(k=0;k<N;k++){
if(S[k]==i-1)break;
}

P[R]=k;
Q[R]=i-1;
R++;
swap(S[k],S[i-1]);

	ok=true;
	for(j=0;j<N;j++){
	if(S[j]!=j)ok=false;
	}
	if(ok)return i;


}

if(R%2==1){
P[R]=0;
Q[R]=0;
R++;
}

}else{//his moves are redundant

for(i=0;i<N-1;i++){//find i, send it to ith position

for(k=0;k<N;k++){
if(S[k]==i)break;
}

P[R]=k;
Q[R]=i;
R++;
swap(S[k],S[i]);

}
/*
for(i=0;i<N;i++){
cout<<S[i]<<" ";
}cout<<endl;*/
while(R>0&&P[R-1]==Q[R-1])R--;


}


	return R;
}


Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:15:39: warning: unused parameter 'M' [-Wunused-parameter]
   15 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                   ~~~~^
sorting.cpp:15:46: warning: unused parameter 'X' [-Wunused-parameter]
   15 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                          ~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 296 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Incorrect 1 ms 204 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 296 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Incorrect 1 ms 204 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Expected integer, but "haha13" found
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 296 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Incorrect 1 ms 204 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -