Submission #60075

# Submission time Handle Problem Language Result Execution time Memory
60075 2018-07-23T15:46:00 Z Eae02 Sorting (IOI15_sorting) C++14
16 / 100
1000 ms 436 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> sInitial(S, S + N);
	
	for (int t = 0; t < M; t++)
	{
		std::vector<int> finalAccess(N, 0);
		for (int i = 0; i < t; i++)
		{
			finalAccess[X[i]] = i;
			finalAccess[Y[i]] = i;
		}
		
		std::copy(all(sInitial), S);
		
		int R = 0;
		for (; R < t; R++)
		{
			if (std::equal(S, S + N, sorted.begin()))
				return R;
			
			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 == t)
				{
					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;
			}
		}
	}
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:66:19: warning: conversion to 'int' from 'long int' may alter its value [-Wconversion]
      Q[R] = valIt - S;
             ~~~~~~^~~
sorting.cpp:76:18: warning: conversion to 'int' from 'long int' may alter its value [-Wconversion]
     Q[R] = valIt - S;
            ~~~~~~^~~
sorting.cpp:80:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1057 ms 436 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1057 ms 436 KB Time limit exceeded
2 Halted 0 ms 0 KB -