답안 #424465

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
424465 2021-06-12T01:21:23 Z Ozy 정렬하기 (IOI15_sorting) C++17
74 / 100
50 ms 17972 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];

    a = cuenta(N + 10, false);
    if (a == N) return 0;


    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:58: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]
   58 |         if (i < intercambios.size()){
      |             ~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 292 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 292 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 300 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 292 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 300 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 460 KB Output is correct
22 Correct 2 ms 460 KB Output is correct
23 Correct 4 ms 460 KB Output is correct
24 Correct 2 ms 460 KB Output is correct
25 Correct 2 ms 548 KB Output is correct
26 Correct 2 ms 460 KB Output is correct
27 Correct 2 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 364 KB Output is correct
2 Correct 17 ms 376 KB Output is correct
3 Correct 14 ms 420 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 4 ms 332 KB Output is correct
7 Correct 13 ms 476 KB Output is correct
8 Correct 15 ms 432 KB Output is correct
9 Correct 17 ms 464 KB Output is correct
10 Correct 18 ms 428 KB Output is correct
11 Correct 18 ms 436 KB Output is correct
12 Correct 13 ms 440 KB Output is correct
13 Correct 25 ms 460 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 364 KB Output is correct
2 Correct 17 ms 376 KB Output is correct
3 Correct 14 ms 420 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 4 ms 332 KB Output is correct
7 Correct 13 ms 476 KB Output is correct
8 Correct 15 ms 432 KB Output is correct
9 Correct 17 ms 464 KB Output is correct
10 Correct 18 ms 428 KB Output is correct
11 Correct 18 ms 436 KB Output is correct
12 Correct 13 ms 440 KB Output is correct
13 Correct 25 ms 460 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Runtime error 50 ms 17972 KB Execution killed with signal 11
16 Halted 0 ms 0 KB -