답안 #1014729

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1014729 2024-07-05T11:01:56 Z MarwenElarbi 정렬하기 (IOI15_sorting) C++17
0 / 100
249 ms 524288 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 < (int)a.size(); ++i)
    {
        while(j<(int)b.size()&&b[j].fi<a[i].fi){
            cur.pb(b[j]);
            j++;
        }
        cur.pb(a[i]);
    }
    while(j<(int)b.size()) cur.pb(b[j++]);
    for (int i = 0; i < (int)cur.size(); ++i)
    {
        x.pb(cur[i].se);
        y.pb(i+l);
        for (int k = 0; k < (int)cur.size(); ++k)
        {
            if(cur[k].se==i+l) cur[k].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});
    }
    swap(tab[0],tab[1]);
    tab[0].se=0;
    tab[1].se=1;
    for (int i = 0; i < N; ++i)
    {
        if(tab[i].fi==0){
            x.pb(i);
            y.pb(0);
            tab[i].fi=tab[0].fi;
            break;
        }
    }
    swap(tab[0],tab[1]);
    tab[0].se=0;
    tab[1].se=1;
    for (int i = 0; i < N; ++i)
    {
        if(tab[i].fi==1){
            x.pb(i);
            y.pb(0);
            tab[i].fi=tab[0].fi;
        }
    }
    daq(2,N-1);
    P[0]=x[0];
    P[1]=x[1];
    Q[0]=y[0];
    Q[1]=y[1];
    for (int i = 2; i < (int)x.size(); ++i)
    {
        P[i]=x[i];
    }
    for (int i = 2; i < (int)y.size(); ++i)
    {
        Q[i]=y[i];
    }
    return (int)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 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
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[]) {
      |                                                   ~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 249 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 249 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 246 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 249 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 1372 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 1372 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -