답안 #519161

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
519161 2022-01-25T18:56:36 Z tabr 정렬하기 (IOI15_sorting) C++17
20 / 100
2 ms 460 KB
#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]) {
    int low = -1;
    int high = m + 1;
    while (high - low > 1) {
        int mid = (high + low) >> 1;
        vector<int> t(n);
        for (int i = 0; i < n; i++) {
            t[i] = s[i];
        }
        for (int i = 0; i < mid; i++) {
            swap(t[x[i]], t[y[i]]);
        }
        vector<pair<int, int>> a;
        vector<int> pos(n);
        for (int i = 0; i < n; i++) {
            pos[t[i]] = i;
        }
        for (int i = 0; i < n; i++) {
            if (t[i] == i) {
                continue;
            }
            int j = pos[i];
            a.emplace_back(i, j);
            swap(t[i], t[j]);
            swap(pos[t[i]], pos[t[j]]);
        }
        if ((int) a.size() <= mid) {
            for (int i = 0; i < mid; i++) {
                if (i >= (int) a.size()) {
                    p[i] = q[i] = 0;
                } else {
                    p[i] = a[i].first;
                    q[i] = a[i].second;
                }
            }
            high = mid;
        } else {
            low = mid;
        }
    }
    return high;
}

#ifdef tabr
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    return 0;
}
#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 0 ms 292 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 0 ms 288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 0 ms 292 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 0 ms 288 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 292 KB Output is correct
11 Correct 0 ms 300 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 288 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 0 ms 292 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 0 ms 288 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 292 KB Output is correct
11 Correct 0 ms 300 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Incorrect 1 ms 288 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -