Submission #317917

# Submission time Handle Problem Language Result Execution time Memory
317917 2020-10-30T19:55:29 Z keta_tsimakuridze Sorting (IOI15_sorting) C++14
0 / 100
2 ms 512 KB
#include<bits/stdc++.h>
#include "sorting.h"
int findSwapPairs(int N, int A[], int M, int x[], int y[], int P[], int Q[]) {
    int l=0; int r=M-1;
    std::vector<std::pair<int,int> > V,ans;
    int a[N+5],ind[N+5];
    while(l<=r){
    	V.clear();
    	int mid=(l+r)/2;
		for(int i=0;i<mid;i++){
			std::swap(a[x[i]],a[y[i]]);
		}
		for(int i=0;i<mid;i++){
			ind[a[i]]=i;
		}
		for(int i=0;i<N;i++){
			if(a[i]!=i){
				int c=ind[i],b=a[i];
				std::swap(a[i],a[ind[i]]);
				V.push_back(std::make_pair(i,ind[i]));
				std::swap(c,ind[b]);	
			}
		}
		if(V.size()<=mid+1) {
			ans.clear();
			ans.resize(mid+1);
			for(int i=V.size();i<mid;i++)
			V.push_back(std::make_pair(0,0));
			ans=V; 
			r=mid-1;
		}
		else l=mid+1;
	} 
	for(int i=0;i<ans.size();i++){
	P[i]=ans[i].first;
	Q[i]=ans[i].second;
	}
	return ans.size();
}
 

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:24:14: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   24 |   if(V.size()<=mid+1) {
      |      ~~~~~~~~^~~~~~~
sorting.cpp:27:20: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   27 |    for(int i=V.size();i<mid;i++)
      |              ~~~~~~^~
sorting.cpp:34:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |  for(int i=0;i<ans.size();i++){
      |              ~^~~~~~~~~~~
sorting.cpp:38:17: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   38 |  return ans.size();
      |         ~~~~~~~~^~
sorting.cpp:3:30: warning: unused parameter 'A' [-Wunused-parameter]
    3 | int findSwapPairs(int N, int A[], int M, int x[], int y[], int P[], int Q[]) {
      |                          ~~~~^~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -