답안 #552895

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
552895 2022-04-24T09:21:15 Z elazarkoren 정렬하기 (IOI15_sorting) C++17
20 / 100
7 ms 340 KB
#include "sorting.h"
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
//#define int ll
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<bool> vb;

const int MAX_N = 2e5 + 5;

int x[MAX_N], y[MAX_N];
int n;

int cnt;

vi Compute(int i, vi s) {
    for (; i < cnt; i++) swap(s[x[i]], s[y[i]]);
    return s;
}

int findSwapPairs(int N, int S[], int m, int X[], int Y[], int p[], int q[]) {
    n = N;
    vi s(n);
    for (int i = 0; i < n; i++) s[i] = S[i], x[i] = X[i], y[i] = Y[i];
    for (int i = 0; i < n; i++) {
        swap(s[x[i]], s[y[i]]);
        vi s2 = Compute(i + 1, s);
        int v1, v2;
        for (int j = 0; j < n; j++) {
            if (s2[j] == i) {
                v1 = s2[i], v2 = s2[j];
            }
        }
        int ind1, ind2;
        for (ind1 = 0; s[ind1] != v1; ind1++);
        for (ind2 = 0; s[ind2] != v2; ind2++);
        p[i] = ind1, q[i] = ind2;
        swap(s[p[i]], s[q[i]]);
        if (is_sorted(all(s))) {
            cnt = i + 1;
            break;
        }
    }
//    for (int i = 0; i < n; i++) s[i] = S[i];
//    for (int i = 0; i < cnt; i++) {
//        swap(s[x[i]], s[y[i]]);
//        swap(s[p[i]], s[q[i]]);
//    }
//    for (int i = 0; i < n; i++) {
//        if (s[i] != i) {
//            return -1;
//        }
//    }
    return cnt;
}
//8
//3 5 6 2 1 7 0 4
//8
//0 1
//0 1
//0 1
//0 1
//0 1
//0 1
//0 1
//0 1

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:29:39: warning: unused parameter 'm' [-Wunused-parameter]
   29 | int findSwapPairs(int N, int S[], int m, int X[], int Y[], int p[], int q[]) {
      |                                   ~~~~^
sorting.cpp:44:32: warning: 'v2' may be used uninitialized in this function [-Wmaybe-uninitialized]
   44 |         for (ind2 = 0; s[ind2] != v2; ind2++);
sorting.cpp:43:32: warning: 'v1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   43 |         for (ind1 = 0; s[ind1] != v1; ind1++);
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 232 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Incorrect 1 ms 232 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -