Submission #484063

# Submission time Handle Problem Language Result Execution time Memory
484063 2021-11-02T03:09:24 Z Cross_Ratio Sorting (IOI15_sorting) C++14
0 / 100
1 ms 332 KB



#include <bits/stdc++.h>
#include "sorting.h"
using namespace std;
typedef pair<long long int, int> P;
vector<P> So;
vector<long long int> S;
vector<int> X, Y;
vector<long long int> idx;
inline int id(long long int n) {
    return lower_bound(idx.begin(),idx.end(),n)-idx.begin();
}
int N;
int findSwapPairs(int N2, int S2[], int M, int X2[], int Y2[], int P1[], int P2[]) {
    N = N2;
    int i, j;
    for(i=0;i<N;i++) {
        S.push_back(S2[i]);
        X.push_back(X2[i]);
        Y.push_back(Y2[i]);
    }
    for(i=0;i<N;i++) {
        S[i] = N * S[i] + i;
        idx.push_back(S[i]);
    }
    sort(idx.begin(),idx.end());
    vector<int> Sk;
    Sk.resize(N);
    for(i=0;i<N;i++) Sk[id(S[i])] = i;
/*
    for(i=0;i<N;i++) cout << Sk[i] << ' ';
    cout << '\n';
*/
    int cnt = 0;
    for(i=2;i<N;i++) {

        if(i == Sk[i]) continue;
        P1[cnt] = i;
        P2[cnt] = Sk[i];
        swap(S[i],S[Sk[i]]);
        Sk[id(S[P1[cnt]])] = P1[cnt];
        Sk[id(S[P2[cnt]])] = P2[cnt];
        cnt++;
        swap(S[0],S[1]);
        Sk[id(S[0])] = 0;
        Sk[id(S[1])] = 1;
/*
        for(int j=0;j<N;j++) cout << S[j]/N << ' ';
        cout << '\n';
        for(int j=0;j<N;j++) cout << Sk[j] << ' ';
        cout << "\n\n";
*/
    }
    if(S[0] < S[1]) {
        P1[cnt] = 0;
        P2[cnt] = 1;
        cnt++;
    }
    //for(i=0;i<N;i++) cout << S[i]/N <<' ';

    return cnt;
}

Compilation message

sorting.cpp: In function 'int id(long long int)':
sorting.cpp:14:48: warning: conversion from '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   14 |     return lower_bound(idx.begin(),idx.end(),n)-idx.begin();
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:19:12: warning: unused variable 'j' [-Wunused-variable]
   19 |     int i, j;
      |            ^
sorting.cpp:17:41: warning: unused parameter 'M' [-Wunused-parameter]
   17 | int findSwapPairs(int N2, int S2[], int M, int X2[], int Y2[], int P1[], int P2[]) {
      |                                     ~~~~^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -