답안 #804111

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
804111 2023-08-03T07:13:18 Z _martynas 정렬하기 (IOI15_sorting) C++11
16 / 100
5 ms 468 KB
#include "sorting.h"
#include <bits/stdc++.h>

using namespace std;

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    int T[N];
    for (int i = 0; i < N; i++) T[i] = S[i];
    for (int i = 0; i < M; i++) swap(T[X[i]], T[Y[i]]);
    for (int i = 0; i < M; i++) P[i] = Q[i] = 0;
    vector<pair<int, int>> swap_list;
    for (int i = 0; i < N; i++) {
        if (T[i] != i) {
            swap_list.emplace_back(i, T[i]);
            for (int j = i+1; j < N; j++) {
                if (T[j] == i) {
                    swap(T[i], T[j]);
                }
            }
        }
    }
    for (int i = 0; i < (int)swap_list.size(); i++) {
        swap(S[X[i]], S[Y[i]]);
        int a, b;
        for (int j = 0; j < N; j++) {
            if (S[j] == swap_list[i].first) a = j;
            if (S[j] == swap_list[i].second) b = j;
        }
        P[i] = a;
        Q[i] = b;
        swap(S[a], S[b]);
    }
    return M;
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:31:22: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
   31 |         swap(S[a], S[b]);
      |                      ^
sorting.cpp:31:16: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
   31 |         swap(S[a], S[b]);
      |                ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 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 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -