Submission #571890

# Submission time Handle Problem Language Result Execution time Memory
571890 2022-06-03T05:19:57 Z kwongweng Sorting (IOI15_sorting) C++17
36 / 100
2 ms 424 KB
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef long long ll;
typedef long double ld;

#define FOR(i,a,b) for(int i = a; i < b; i++)
#define ROF(i,a,b) for(int i = a; i >= b; i--)
#define fi first
#define se second
#define pb push_back

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
	int pos[N];
	FOR(i,0,N){
		pos[S[i]] = i;
	}
	vi s(N); FOR(i,0,N) s[i] = S[i];
	if (X[0]==Y[0]){
		int cnt = 0;
		FOR(i,0,N-1){
			if (pos[i] == i) continue;
			P[cnt] = pos[i];
			Q[cnt] = i;
			cnt++;
			s[pos[i]] = s[i];
			pos[s[i]] = pos[i];
		}
		return cnt;
	}
	FOR(i,0,N-1){
		if (X[i] != Y[i]){
			swap(pos[S[X[i]]], pos[S[Y[i]]]);
			swap(S[X[i]], S[Y[i]]);
		}
		if (i == N-2){
			if (S[0] == 0){
				P[i] = 0; Q[i] = 0;
			}else{
				P[i] = 0, Q[i] = 1;
			}
			if (P[i] != Q[i]){
				swap(pos[S[P[i]]], pos[S[Q[i]]]);
				swap(S[P[i]], S[Q[i]]);
			}
			break;
		}	
		P[i] = pos[i+2];
		Q[i] = i+2;
		if (P[i] != Q[i]){
			swap(pos[S[P[i]]], pos[S[Q[i]]]);
			swap(S[P[i]], S[Q[i]]);
		}
	}
	return N-1;
}


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[]) {
      |                                   ~~~~^
# 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 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 300 KB Output is correct
# 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 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 300 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 360 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 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 0 ms 212 KB Output is correct
# 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 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 300 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 360 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 300 KB Output is correct
20 Correct 1 ms 300 KB Output is correct
21 Incorrect 2 ms 424 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -