Submission #1053725

# Submission time Handle Problem Language Result Execution time Memory
1053725 2024-08-11T16:16:47 Z XJP12 Sorting (IOI15_sorting) C++14
36 / 100
1 ms 604 KB
#include <bits/stdc++.h>
#include "sorting.h"
using namespace std;
typedef vector<int> vi;
int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]) {
	int r=0;
	bool ban=true;
	for(int i=0; i<n; i++){
		if(s[i]!=i){
			ban=false;
			break;
		}
	}
	if (ban) return 0;
    if(y[0]==1){
		for(int i=0; i<n; i++){
			ban=true;
			for(int j=0; j<n; j++){
				if(s[j]!=j){
					ban=false;
					break;
				}
			}
			if (ban){ 
				break;
			}	
			swap(s[1], s[0]);
			r++;
			/*for(int j=0; j<n; j++){
				cout<<s[j]<<" ";
			}*/
		//	cout<<endl;
		
			for(int j=0; j<n; j++){
				if(s[j]==i){
					if(s[i]==0 && i==1){
						p[r-1]=j;
						q[r-1]=i-1;
						swap(s[i-1], s[j]);
					}else{
					p[r-1]=j;
					q[r-1]=i;
					swap(s[i], s[j]);
					}
					break;
				}
			}
		/*	for(int j=0; j<n; j++){
				cout<<s[j]<<" ";
			}
			cout<<endl<<endl;*/
		}
		if(s[1]!=1 && s[0]!=0){
			p[r]=0;
			q[r]=1;
			r++;
		}
			/*for(int i=0; i<r; i++){
			cout<<p[i]<<" "<<q[i]<<endl;
		}*/
	}else{
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				if(s[j]==i && j!=i){
					r++;
					p[r-1]=j;
					q[r-1]=i;
					swap(s[i], s[j]);
					break;
				}
			}
		/*	for(int j=0; j<n; j++){
				cout<<s[j]<<" ";
			}
			cout<<endl;*/
		}
	/*	for(int i=0; i<r; i++){
			cout<<p[i]<<" "<<q[i]<<endl;
		}*/
	}
	return r;
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:5:39: warning: unused parameter 'm' [-Wunused-parameter]
    5 | int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]) {
      |                                   ~~~~^
sorting.cpp:5:46: warning: unused parameter 'x' [-Wunused-parameter]
    5 | 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 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Incorrect 1 ms 604 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -