Submission #832675

# Submission time Handle Problem Language Result Execution time Memory
832675 2023-08-21T13:36:48 Z AkramElOmrani Sorting (IOI15_sorting) C++17
54 / 100
206 ms 720 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[]) {
	int ans = 0;
	for(int round = 0; round < m; ++round) {
		if(is_sorted(s, s + n)) {
			return ans;
		}
		swap(s[x[round]], s[y[round]]);
		// we assume that after m rounds it will def be swapped
		vector<int> ord(n); iota(ord.begin(), ord.end(), 0);
		// ord[i] = i; at last since it's sorted
		for(int j = m - 1; j > round; --j) {
			swap(ord[x[j]], ord[y[j]]);
		}

		for(int i = 0; i < n; ++i) {
			if(s[i] != ord[i]) { // ith element isn't in its place look for who is in its place
				for(int k = i + 1; k < n; ++k) {
					if(s[k] == ord[i]) {
						swap(s[k], s[i]);
						p[ans] = k;
						q[ans] = i;
						goto end;
					}
				}
			}
		}
		p[ans] = q[ans] = n - 1; // already sorted no change needed
		end:;
		++ans;
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 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 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 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 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 300 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 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 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 300 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 300 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 300 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 135 ms 720 KB Output is correct
22 Correct 130 ms 696 KB Output is correct
23 Correct 206 ms 672 KB Output is correct
24 Correct 133 ms 692 KB Output is correct
25 Correct 141 ms 692 KB Output is correct
26 Correct 137 ms 648 KB Output is correct
27 Correct 131 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 432 KB Output isn't correct
2 Halted 0 ms 0 KB -