답안 #60060

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
60060 2018-07-23T14:55:06 Z Eae02 정렬하기 (IOI15_sorting) C++14
0 / 100
3 ms 512 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]]);
		
		auto it = std::find_if(all(finalAccess), [&](int a) { return R >= a; });
		if (it == finalAccess.end())
		{
			P[R] = Q[R] = 0;
			continue;
		}
		
		int index = it - finalAccess.begin();
		int val = sorted[index];
		auto valIt = std::find(S, S + N, index);
		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:33:18: warning: conversion to 'int' from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type {aka long int}' may alter its value [-Wconversion]
   int index = it - finalAccess.begin();
               ~~~^~~~~~~~~~~~~~~~~~~~~
sorting.cpp:39:16: warning: conversion to 'int' from 'long int' may alter its value [-Wconversion]
   Q[R] = valIt - S;
          ~~~~~~^~~
sorting.cpp:34:7: warning: unused variable 'val' [-Wunused-variable]
   int val = sorted[index];
       ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Incorrect 3 ms 256 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Incorrect 3 ms 256 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 432 KB Output is correct
2 Incorrect 3 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Incorrect 3 ms 256 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -