답안 #424462

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
424462 2021-06-12T01:19:06 Z Ozy 정렬하기 (IOI15_sorting) C++17
0 / 100
18 ms 632 KB
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repa(i,a,b) for (int i = (a); i >= (b); i--)
#define lli long long int
#define debugsl(a) cout << #a << " = " << a << ", "
#define debug(a) cout << #a << " = " << a << endl

int a, b, n,cant,me;
int visitados[2002],id[2002],glob[2002];
int arr[2002],x[2002],y[2002],p[2002],q[2002];
vector<pair<int, int> > intercambios;

int cuenta(int c, bool guarda) {
    int act,res = 0;

    rep(i,0,n-1) {
        if (visitados[i] != c) {
            res++;

            act = arr[i];
            visitados[i] = c;

            if (guarda && act != arr[act]) intercambios.emplace_back(act, arr[act]);
            while (act != i) {
                visitados[act] = c;
                act = arr[act];
                if (guarda && act != i) intercambios.emplace_back(act, arr[act]);
            }
        }
    }

    return res;
}

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

    n = N;
    rep(i,0,n-1) arr[i] = S[i];

    rep(i,0,M-1) {
        swap(arr[X[i]], arr[Y[i]]);
        a = N - cuenta(i + 1, false);
        if (a <= (i+1)){
            me = i;
            break;
        }
    }
    cuenta(me + 2, true);

    rep(i, 0, me){
        swap(S[X[i]], S[Y[i]]);
        if (i < intercambios.size()){
            rep(j, 0, N - 1){
                if (S[j] == intercambios[i].first) a = j;
                else if (S[j] == intercambios[i].second) b = j;
            }
            P[i] = a;
            Q[i] = b;
            swap(S[a], S[b]);
        }
        else {
            P[i] = Q[i] = 0;
        }
    }

	return me + 1;
}


Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:54:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         if (i < intercambios.size()){
      |             ~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 416 KB Output is correct
2 Correct 18 ms 484 KB Output is correct
3 Correct 18 ms 632 KB Output is correct
4 Incorrect 1 ms 332 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 416 KB Output is correct
2 Correct 18 ms 484 KB Output is correct
3 Correct 18 ms 632 KB Output is correct
4 Incorrect 1 ms 332 KB Output isn't correct
5 Halted 0 ms 0 KB -