답안 #794910

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
794910 2023-07-27T03:20:47 Z Username4132 정렬하기 (IOI15_sorting) C++14
54 / 100
27 ms 3412 KB
#include "sorting.h"
#include<iostream>
#include<algorithm>
using namespace std;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define forsn(i, s, n) for(int i=s; i<(int)n; ++i)

const int MAXN = 610;
int n, cou, ans, arr[MAXN][MAXN];

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
	n=N;
	forn(i, n) arr[0][i]=S[i];
	forn(i, n-1){
		forn(j, n) arr[i+1][j]=arr[i][j];
		swap(arr[i+1][X[i]], arr[i+1][Y[i]]);
	}
	forn(i, n-1){
		int num = arr[n-1][i];
		forsn(j, i+1, n){
			int x = find(arr[j], arr[j]+n, num) - arr[j];
			int y = find(arr[j], arr[j]+n, i) - arr[j];
			swap(arr[j][x], arr[j][y]);
			if(j==i+1) P[cou]=x, Q[cou]=y, ++cou;
		}
	}
	while(true){
		bool flag=true;
		forn(i, n) flag&=(S[i]==i);
		if(flag) break;
		swap(S[X[ans]], S[Y[ans]]);
		swap(S[P[ans]], S[Q[ans]]);
		++ans;
	}
	return ans;
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:21:40: warning: conversion from 'long int' to 'int' may change value [-Wconversion]
   21 |    int x = find(arr[j], arr[j]+n, num) - arr[j];
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
sorting.cpp:22:38: warning: conversion from 'long int' to 'int' may change value [-Wconversion]
   22 |    int y = find(arr[j], arr[j]+n, i) - arr[j];
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
sorting.cpp:11:39: warning: unused parameter 'M' [-Wunused-parameter]
   11 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                   ~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 224 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 0 ms 224 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 312 KB Output is correct
21 Correct 24 ms 1620 KB Output is correct
22 Correct 24 ms 1620 KB Output is correct
23 Correct 27 ms 1620 KB Output is correct
24 Correct 21 ms 1620 KB Output is correct
25 Correct 21 ms 1724 KB Output is correct
26 Correct 22 ms 1620 KB Output is correct
27 Correct 21 ms 1620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 3412 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 3412 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -