Submission #590864

# Submission time Handle Problem Language Result Execution time Memory
590864 2022-07-06T12:28:29 Z FatihSolak Sorting (IOI15_sorting) C++17
0 / 100
1 ms 596 KB
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]) {
	if(is_sorted(s,s+n))
		return 0;
	for(int i = 0;i<m;i++){
		p[i] = q[i] = 0;
	}
	vector<int> fnal;
	vector<int> now;
	vector<int> pfnal(n,0);
	vector<int> pnow(n,0);
	int cnt = 0;
	for(int i = 0;i<n;i++){
		fnal.push_back(s[i]);
		pfnal[s[i]] = i;
		now.push_back(s[i]);
		pnow[s[i]] = i;
		cnt += (s[i] == i);
	}
	for(int i = 0;i<m;i++){
		swap(pfnal[fnal[x[i]]],pfnal[fnal[y[i]]]);
		swap(fnal[x[i]],fnal[y[i]]);
	}
	for(int i = 0;i<m;i++){
		swap(pnow[now[x[i]]],pnow[now[y[i]]]);
		swap(now[x[i]],now[y[i]]);
		if(i < n){
			int ps1 = pnow[i];
			int ps2 = pnow[fnal[i]];
			p[i] = ps1;
			q[i] = ps2;
			swap(pnow[now[ps1]],pnow[now[ps2]]);
			swap(now[ps1],now[ps2]);
			swap(pfnal[fnal[i]],pfnal[i]);
			swap(fnal[i],fnal[pfnal[i]]);
		}
		if(is_sorted(now.begin(),now.end()))
			return i+1;
	}
	assert(0);
}


# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Runtime error 1 ms 340 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Runtime error 1 ms 340 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 340 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Runtime error 1 ms 340 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 596 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 596 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -