답안 #60064

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
60064 2018-07-23T15:07:56 Z Eae02 정렬하기 (IOI15_sorting) C++14
36 / 100
30 ms 640 KB
#include "sorting.h"

#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[])
{
	std::vector<int> sorted(S, S + N);
	std::sort(all(sorted));
	
	std::vector<int> finalAccess(N);
	for (int i = 0; i < M; i++)
	{
		finalAccess[X[i]] = i;
		finalAccess[Y[i]] = i;
	}
	
	int R = 0;
	for (; R < M; R++)
	{
		if (std::equal(S, S + N, sorted.begin()))
			break;
		
		std::swap(S[X[R]], S[Y[R]]);
		
		int index = -1;
		for (int i = 0; i < N; i++)
		{
			if (R >= finalAccess[i] && S[i] != sorted[i])
			{
				index = i;
				break;
			}
		}
		
		if (index == -1)
		{
			for (int i = 0; i < N; i++)
			{
				if (R + 1 == finalAccess[i] && S[i] != sorted[i])
				{
					index = i;
					break;
				}
			}
			
			if (index == -1 || R + 1 == M)
			{
				P[R] = Q[R] = 0;
			}
			else
			{
				int val = sorted[index];
				int target = X[R + 1] == index ? Y[R + 1] : X[R + 1];
				
				auto valIt = std::find(S, S + N, val);
				std::swap(S[target], *valIt);
				
				P[R] = target;
				Q[R] = valIt - S;
			}
		}
		else
		{
			int val = sorted[index];
			auto valIt = std::find(S, S + N, val);
			std::swap(S[index], *valIt);
			
			P[R] = index;
			Q[R] = valIt - S;
		}
	}
	
	return R;
}


Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:60:18: warning: conversion to 'int' from 'long int' may alter its value [-Wconversion]
     Q[R] = valIt - S;
            ~~~~~~^~~
sorting.cpp:70:17: warning: conversion to 'int' from 'long int' may alter its value [-Wconversion]
    Q[R] = valIt - S;
           ~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 460 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 460 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 460 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Incorrect 15 ms 640 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 30 ms 476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 30 ms 476 KB Output isn't correct
2 Halted 0 ms 0 KB -