답안 #761965

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
761965 2023-06-20T12:55:37 Z Ahmed57 정렬하기 (IOI15_sorting) C++17
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>
using namespace std;
int lol[100001],vis[100001];
vector<int> v;
void dfs(int i){
    vis[i] = 1;
    v.push_back(i);
    if(vis[lol[i]]==0)dfs(lol[i]);
}
int findSwapPairs(int N,int S[],int M,int X[],int Y[],int P[],int Q[]){
    int ans = 0;
    swap(S[0],S[1]);
    int on = 0 , ze = 0;
    for(int i = 0;i<N;i++){
        if(S[i]==0)ze = i;
        if(S[i]==1)on = i;
    }
    if(ze>1){
        swap(S[(on?0:1)],S[ze]);
        P[0] = ze , Q[0] = (on?0:1);
        //cout<<ze<<"hh"<<endl;
        ans++;
        swap(S[0],S[1]);
        if(on>1){
            swap(S[0],S[on]);
            P[1] = 0 , Q[1] = on;
            ans++;
            swap(S[0],S[1]);
        }
    }else if(on>1){
        if(ze==0){
            P[0] = on;
            Q[0] = 1;
            ans++;
        }else{
            P[0] = on;
            Q[0] = 0;
            ans++;
        }
        swap(S[0],S[1]);
    }
    for(int i = 0;i<N;i++){
        lol[i] = S[i];
        vis[i] = 0;
    }
    int ha = -1;
    for(int i = 2;i<N;i++){
        if(vis[i]==0){
            v.clear();
            dfs(i);
            for(int j = 1;j<v.size();j++){
                ha++;
                P[ans] = v[0];
                Q[ans] = v[j];
                ans++;
            }
        }
    }
    if(ha==-1){
        if(S[0]==1){
            return ans;
        }else{
            P[ans] = 0;
            Q[ans] = 0;
            ans++;
            return ans;
        }
    }else{
        int pr = ha%2;
        if(S[pr]==0){
            return ans;
        }else{
            P[ans] = 0;
            Q[ans] = 0;
            ans++;
            return ans;
        }
    }
}
/*
int main(){
    int S[] = {0,1,2,4,3};
    int X[] = {0,0,0,0,0,0,0,0,0,0,0};
    int Y[] = {1,1,1,1,1,1,1,1,1,1,1};
    cout<<findSwapPairs(5,S,100,X,Y)<<endl;
    for(int i = 0;i<10;i++){
        cout<<P[i]<<" "<<Q[i]<<endl;
    }
}
*/

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:51:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |             for(int j = 1;j<v.size();j++){
      |                           ~^~~~~~~~~
sorting.cpp:10:37: warning: unused parameter 'M' [-Wunused-parameter]
   10 | int findSwapPairs(int N,int S[],int M,int X[],int Y[],int P[],int Q[]){
      |                                 ~~~~^
sorting.cpp:10:43: warning: unused parameter 'X' [-Wunused-parameter]
   10 | int findSwapPairs(int N,int S[],int M,int X[],int Y[],int P[],int Q[]){
      |                                       ~~~~^~~
sorting.cpp:10:51: warning: unused parameter 'Y' [-Wunused-parameter]
   10 | int findSwapPairs(int N,int S[],int M,int X[],int Y[],int P[],int Q[]){
      |                                               ~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -