Submission #1014681

# Submission time Handle Problem Language Result Execution time Memory
1014681 2024-07-05T09:21:38 Z MarwenElarbi Sorting (IOI15_sorting) C++17
0 / 100
6 ms 1372 KB
#include <bits/stdc++.h>
#include "sorting.h"
using namespace std;
#define ll long long
#define pb push_back
#define se second
#define fi first
vector<pair<int,int>> tab;
vector<int> x,y;
int cnt=0;
vector<pair<int,int>> daq(int l,int r){
    if(l==r) return {tab[l]};
    int mid=(r+l)/2;
    vector<pair<int,int>> none;
    vector<pair<int,int>> a=daq(l,mid);
    vector<pair<int,int>> b=( mid+1<=r ? daq(mid+1,r) : none);
    int j=0;
    vector<pair<int,int>> cur;
    for (int i = 0; i < a.size(); ++i)
    {
        if(j<b.size()&&b[j].fi<a[i].fi){
            cur.pb(b[j]);
            j++;
        }
        cur.pb(a[i]);
    }
    while(j<b.size()) cur.pb(b[j++]);
    for (int i = 0; i < cur.size(); ++i)
    {
        x.pb(cur[i].se);
        y.pb(i+l);
        for (int j = 0; j < cur.size(); ++j)
        {
            if(cur[j].se==i+l) cur[j].se=cur[i].se;
        }
        cur[i].se=i+l;
    }
    return cur;
}
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    for (int i = 0; i < N; ++i)
    {
        tab.pb({S[i],i});
    }
    /*bool test=(Y[0]==1);
    if(test) swap(tab[0].se,tab[1].se);
    sort(tab.begin(),tab.end());
    for (int i = 0; i < N; ++i) if(tab[i].se==0) swap(tab[i].se,tab[0^test].se);
    P[cnt]=tab[0].se;
    Q[cnt]=0;
    cnt++;
    if(test) swap(tab[0].se,tab[1].se);
    for (int i = 0; i < N; ++i) if(tab[i].se==1) swap(tab[i].se,tab[1^test].se);
    P[cnt]=tab[1].se;
    Q[cnt]=1^test;
    cnt++;
    for (int i = 2; i < N; ++i)
    {
        tab[i]={S[i],i};
    }*/
    daq(0,N-1);
    for (int i = 0; i < x.size(); ++i)
    {
        P[i]=x[i];
    }
    for (int i = 0; i < y.size(); ++i)
    {
        Q[i]=y[i];
    }
    return x.size();
}
/*
int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int N, M;
    cin>>N;
    int *S = (int*)malloc(sizeof(int) * (unsigned int)N);
    for (int i = 0; i < N; ++i)
        cin>>S[i];
    cin>>M;
    int *X = (int*)malloc(sizeof(int) * (unsigned int)M), *Y = (int*)malloc(sizeof(int) * (unsigned int)M);
    for (int i = 0; i < M; ++i) {
        cin>>X[i]>>Y[i];    
    }
    int *P = (int*)malloc(sizeof(int) * (unsigned int)M), *Q = (int*)malloc(sizeof(int) * (unsigned int)M);
    int ans = findSwapPairs(N, S, M, X, Y, P, Q);
    cout <<ans<<endl;
    for (int i = 0; i < ans; ++i)
        cout <<P[i]<<" "<<Q[i]<<endl;
    return 0;
}*/

Compilation message

sorting.cpp: In function 'std::vector<std::pair<int, int> > daq(int, int)':
sorting.cpp:19:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for (int i = 0; i < a.size(); ++i)
      |                     ~~^~~~~~~~~~
sorting.cpp:21:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |         if(j<b.size()&&b[j].fi<a[i].fi){
      |            ~^~~~~~~~~
sorting.cpp:27:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     while(j<b.size()) cur.pb(b[j++]);
      |           ~^~~~~~~~~
sorting.cpp:28:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for (int i = 0; i < cur.size(); ++i)
      |                     ~~^~~~~~~~~~~~
sorting.cpp:32:18: warning: declaration of 'j' shadows a previous local [-Wshadow]
   32 |         for (int j = 0; j < cur.size(); ++j)
      |                  ^
sorting.cpp:17:9: note: shadowed declaration is here
   17 |     int j=0;
      |         ^
sorting.cpp:32:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for (int j = 0; j < cur.size(); ++j)
      |                         ~~^~~~~~~~~~~~
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:62:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for (int i = 0; i < x.size(); ++i)
      |                     ~~^~~~~~~~~~
sorting.cpp:66:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |     for (int i = 0; i < y.size(); ++i)
      |                     ~~^~~~~~~~~~
sorting.cpp:70:18: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   70 |     return x.size();
      |            ~~~~~~^~
sorting.cpp:40:39: warning: unused parameter 'M' [-Wunused-parameter]
   40 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                   ~~~~^
sorting.cpp:40:46: warning: unused parameter 'X' [-Wunused-parameter]
   40 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                          ~~~~^~~
sorting.cpp:40:55: warning: unused parameter 'Y' [-Wunused-parameter]
   40 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                                   ~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 432 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 432 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 432 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 1372 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 1372 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -