답안 #1018841

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1018841 2024-07-10T10:07:27 Z amirhoseinfar1385 정렬하기 (IOI15_sorting) C++17
0 / 100
2 ms 6492 KB
#include "sorting.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn=1000000+10;
int all[maxn],n,q,fake[maxn],vis[maxn];
pair<int,int>alltagh[maxn];

vector<vector<int>> besaz(int ind){
	vector<vector<int>>ret;
	for(int i=0;i<n;i++){
		fake[i]=all[i];
		vis[i]=0;
	}
	for(int i=1;i<=ind;i++){
		swap(fake[alltagh[i].first],fake[alltagh[i].second]);
	}
	for(int i=0;i<n;i++){
		if(vis[i]==0){
			ret.push_back({});
			int now=i;
			while(vis[now]==0){
		//		cout<<now<<" "<<fake[now]<<endl;
				vis[now]=1;
				ret.back().push_back(now);
				now=fake[now];
			}
		}
	}
	return ret;
}

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    n=N;
    for(int i=0;i<n;i++){
    	all[i]=S[i];
    }
    q=M;
    for(int i=1;i<=q;i++){
    	alltagh[i]=make_pair(X[i-1],Y[i-1]);
    }
   	vector<vector<int>>ger=besaz(q);
   	int now=0;
   	for(int i=0;i<(int)ger.size();i++){
   		int tof=ger[i][0];
   		for(int j=1;j<(int)ger[i].size();j++){
   			P[now]=ger[i][j];
   			Q[now]=tof;
   			now++;
   		}
   	}
	return q;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 6492 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -