제출 #170906

#제출 시각아이디문제언어결과실행 시간메모리
170906socho정렬하기 (IOI15_sorting)C++14
20 / 100
53 ms560 KiB
#include "sorting.h"
#include "bits/stdc++.h"
using namespace std;

const int MXN = 200005;
int n, m;
int seq[MXN];
pair<int, int> plan[MXN];
vector<pair<int, int> > ans;

bool works(int sw) {
	// cout << "try: " << sw << ' ';
	ans.clear();
	int nsw[n];
	for (int i=0; i<n; i++) nsw[i] = seq[i];
	int where[n];
	for (int i=0; i<sw; i++) {
		int a = plan[i].first, b = plan[i].second;
		swap(nsw[a], nsw[b]);
	}
	for (int i=0; i<n; i++) {
		where[nsw[i]] = i;
	}
	int need = 0;
	for (int i=0; i<n; i++) {
		if (nsw[i] == i) continue;
		need++;
		int ati = nsw[i];
		int whei = where[i];
		where[ati] = whei;
		where[i] = i;
		nsw[i] = i;
		nsw[whei] = ati;
		ans.push_back(make_pair(i, whei));
	}
	// cout << (need <= sw) << endl;
	// if (sw == 3) return true;
	return need <= sw;
}

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {

    
    n = N;
    m = M;
    for (int i=0; i<n; i++) seq[i] = S[i];
    for (int i=0; i<m; i++) {
		plan[i].first = X[i];
		plan[i].second = Y[i];
	}
    
    for (int j=0; j<=M; j++) {
		if (works(j)) {
			for (int i=0; i<j; i++) {
				P[i] = ans[i].first;
				Q[i] = ans[i].second;
			}
			return j;
		}
	}
    
}

컴파일 시 표준 에러 (stderr) 메시지

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:62:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...