답안 #1014658

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1014658 2024-07-05T08:59:04 Z MarwenElarbi 정렬하기 (IOI15_sorting) C++17
0 / 100
1 ms 600 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){
            x.pb(b[j].se);
            y.pb(a[i].se);
            swap(a[i].se,b[j].se);
            cur.pb(b[j]);
            j++;
        }
        cur.pb(a[i]);
    }
    while(j<b.size()) cur.pb(b[j++]);
    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)
    {
        cnt++;
        P[i]=x[i];
    }
    for (int i = 0; i < y.size(); ++i)
    {
        Q[i]=y[i];
    }
    return cnt;
}
/*
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:30: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]
   30 |     while(j<b.size()) cur.pb(b[j++]);
      |           ~^~~~~~~~~
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:55:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for (int i = 0; i < x.size(); ++i)
      |                     ~~^~~~~~~~~~
sorting.cpp:60:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for (int i = 0; i < y.size(); ++i)
      |                     ~~^~~~~~~~~~
sorting.cpp:33:39: warning: unused parameter 'M' [-Wunused-parameter]
   33 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                   ~~~~^
sorting.cpp:33:46: warning: unused parameter 'X' [-Wunused-parameter]
   33 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                          ~~~~^~~
sorting.cpp:33:55: warning: unused parameter 'Y' [-Wunused-parameter]
   33 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                                   ~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 600 KB Integer parameter [name=R] equals to 5653, violates the range [0, 5400]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 600 KB Integer parameter [name=R] equals to 5653, violates the range [0, 5400]
2 Halted 0 ms 0 KB -