제출 #252213

#제출 시각아이디문제언어결과실행 시간메모리
252213HeheheSorting (IOI15_sorting)C++14
36 / 100
1 ms512 KiB
#include<bits/stdc++.h> //:3
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define pi pair <int, int>
#define sz(x) (int)((x).size())
#include "sorting.h"

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

const ll H = 2e3 + 11;

//ifstream in(".in");
//ofstream out(".out");

int pos[H];

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {

    int n = N, m = M, cur = 0;


    for(int i = 0; i < n; i++){
        pos[S[i]] = i;
        if(X[i] == 0 && Y[i] == 0)cur++;
    }

    vector<pi>ans;

    if(X[0] == 0 && Y[0] == 0){//subtask 1, 2

        for(int i = 0; i < n; i++){
            if(S[i] == i)continue;
            ans.push_back({i, pos[i]});
            int x = i, y = S[i];
            swap(S[i], S[pos[i]]);
            pos[y] = pos[i];
            pos[x] = x;
        }

        int k = 0;
        for(auto it : ans){
            P[k] = it.ff;
            Q[k] = it.ss;
            k++;
        }

        return sz(ans);
    }else{//subtask 3

 /*       swap(S[0], S[1]); //Ermek first move
        pos[S[0]] = 0;
        pos[S[1]] = 1;*/


        for(int i = n - 1; i >= 1; i--){
            if(S[i] == i)continue;
            
            //his move
            swap(S[0], S[1]);
            pos[S[0]] = 0;
            pos[S[1]] = 1;
            
            ans.push_back({i, pos[i]});

            int x = i, y = S[i];

            swap(S[i], S[pos[i]]);

            pos[y] = pos[i];
            pos[x] = x;

        }

        int k = 0;
        for(auto it : ans){
            P[k] = it.ff;
            Q[k] = it.ss;
            k++;
        }

        return sz(ans);

    }
}

컴파일 시 표준 에러 (stderr) 메시지

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:26:16: warning: unused variable 'm' [-Wunused-variable]
     int n = N, m = M, cur = 0;
                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...