Submission #1081603

#TimeUsernameProblemLanguageResultExecution timeMemory
1081603TrumlingSorting (IOI15_sorting)C++11
0 / 100
1 ms348 KiB
#include "sorting.h" #include<bits/stdc++.h> using namespace std; #define F first #define S second #define pb push_back #define all(x) x.begin(),x.end() #define INF 9999999999999999 typedef long long ll; int findSwapPairs(int N, int ar[], int M, int X[], int Y[], int P[], int Q[]) { int pos[N]; int arr[N]; for(int i=0;i<N;i++) { arr[i]=ar[i]; pos[arr[i]]=i; } vector<pair<int,int>>v; for(int i=0;i<N;i++) { if(pos[i]==i) v.pb({0,0}); else v.pb({pos[i],i}); swap(arr[pos[i]],arr[i]); pos[arr[pos[i]]]=pos[i]; pos[i]=i; } for(int i=0;i<N;i++) arr[i]=ar[i]; for(int i=0;i<v.size();i++) { P[i]=v[i].F; Q[i]=v[i].S; swap(arr[v[i].F],arr[v[i].S]); } assert(is_sorted(arr,arr+N)); return v.size(); }

Compilation message (stderr)

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:31:7: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
   31 |       else
      |       ^~~~
sorting.cpp:33:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
   33 |         swap(arr[pos[i]],arr[i]);
      |         ^~~~
sorting.cpp:43: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]
   43 |  for(int i=0;i<v.size();i++)
      |              ~^~~~~~~~~
sorting.cpp:51:18: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   51 |     return v.size();
      |            ~~~~~~^~
sorting.cpp:14:40: warning: unused parameter 'M' [-Wunused-parameter]
   14 | int findSwapPairs(int N, int ar[], int M, int X[], int Y[], int P[], int Q[])
      |                                    ~~~~^
sorting.cpp:14:47: warning: unused parameter 'X' [-Wunused-parameter]
   14 | int findSwapPairs(int N, int ar[], int M, int X[], int Y[], int P[], int Q[])
      |                                           ~~~~^~~
sorting.cpp:14:56: warning: unused parameter 'Y' [-Wunused-parameter]
   14 | int findSwapPairs(int N, int ar[], int M, int X[], int Y[], int P[], int Q[])
      |                                                    ~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...