Submission #421176

# Submission time Handle Problem Language Result Execution time Memory
421176 2021-06-08T20:33:02 Z Pbezz Sorting (IOI15_sorting) C++14
0 / 100
4 ms 460 KB
#include "sorting.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define pb push_back
typedef pair<ll,ll> pii;

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ll MAXN=2e5+5;
const ll INF=1e9+7;
map<ll,ll>ord;
//ord[k] e a ordem de k

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    P[0] = 0;
	Q[0] = 0;
	vector<ll>seq(N);
	ll i,k,R=0;

for(i=0;i<N;i++){
	seq[i]=S[i];
}
sort(seq.begin(),seq.end());
for(i=0;i<N;i++){
	ord[seq[i]]=i+1;
}

for(i=0;i<N;i++){
	S[i]=ord[S[i]];
}
//S[i] e agora uma permutaçao de tamanho N

if(Y[0]==1){
swap(S[0],S[1]);

for(k=0;k<N;k++){
if(S[k]==1)break;
}

P[R]=k;
Q[R]=1;
R++;
swap(S[k],S[1]);
swap(S[0],S[1]);
//agora, 1 esta em posiçao e vamos meter o 2

for(k=0;k<N;k++){
if(S[k]==2)break;
}

P[R]=k;
Q[R]=1;
R++;
swap(S[k],S[1]);
//esta tudo bem, continuar

for(i=3;i<=N;i++){//find i, send it to ith position

for(k=0;k<N;k++){
if(S[k]==i)break;
}

P[R]=k;
Q[R]=i-1;
R++;
swap(S[k],S[i-1]);

}

if(R%2==1){
P[R]=0;
Q[R]=0;
R++;
}

}else{//his moves are redundant

for(i=1;i<=N;i++){//find i, send it to ith position

for(k=0;k<N;k++){
if(S[k]==i)break;
}

P[R]=k;
Q[R]=i-1;
R++;
swap(S[k],S[i-1]);

}

}
	return R;
}


Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:34:15: warning: conversion from 'std::map<long long int, long long int>::mapped_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
   34 |  S[i]=ord[S[i]];
      |               ^
sorting.cpp:45:6: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   45 | P[R]=k;
      |      ^
sorting.cpp:56:6: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   56 | P[R]=k;
      |      ^
sorting.cpp:68:6: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   68 | P[R]=k;
      |      ^
sorting.cpp:69:7: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   69 | Q[R]=i-1;
      |      ~^~
sorting.cpp:89:6: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   89 | P[R]=k;
      |      ^
sorting.cpp:90:7: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   90 | Q[R]=i-1;
      |      ~^~
sorting.cpp:97:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   97 |  return R;
      |         ^
sorting.cpp:19:39: warning: unused parameter 'M' [-Wunused-parameter]
   19 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                   ~~~~^
sorting.cpp:19:46: warning: unused parameter 'X' [-Wunused-parameter]
   19 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                          ~~~~^~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 292 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 292 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 296 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 292 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -