답안 #727391

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
727391 2023-04-20T14:49:17 Z vjudge1 정렬하기 (IOI15_sorting) C++11
20 / 100
3 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[]) {
        for (int i = 0; i < M; i++) P[i] = Q[i] = 0;
        auto solve = [&](int lim) {
                vector<int> a(M), b(M), ok(N, 0);
                for (int i = 0; i < N; i++) a[i] = S[i];
                for (int i = 0; i < lim; i++) swap(a[X[i]], a[Y[i]]);
                for (int i = 0; i < N; i++) b[a[i]] = i;
                vector<pair<int, int>> changes;
                for (int i = 0; i < N; i++) {
                        if (a[i] != i) {
                                changes.emplace_back(i, b[i]);
                                int pos = b[i];
                                swap(b[a[i]], b[a[b[i]]]);
                                swap(a[i], a[pos]);
                        }
                }
                if (changes.size() > lim) return 0;
                for (int i = 0; i < N; i++) a[i] = S[i];
                for (int i = 0; i < N; i++) b[a[i]] = i;
                for (int i = 0; i < changes.size(); i++) {
                        swap(b[a[X[i]]], b[a[Y[i]]]);
                        swap(a[X[i]], a[Y[i]]);
                        P[i] = b[changes[i].first];
                        Q[i] = b[changes[i].second];
                }
                return 1;
        };
        int l = 0, r = M, res = -1;
        while (l <= r) {
                if (solve(l + r >> 1)) {
                        res = l + r >> 1;
                        r = (l + r >> 1) - 1;
                } else {
                        l = (l + r >> 1) + 1;
                }
        }
        assert(solve(res));
        return res;
}

Compilation message

sorting.cpp: In lambda function:
sorting.cpp:22:36: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   22 |                 if (changes.size() > lim) return 0;
      |                     ~~~~~~~~~~~~~~~^~~~~
sorting.cpp:25:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |                 for (int i = 0; i < changes.size(); i++) {
      |                                 ~~^~~~~~~~~~~~~~~~
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:35:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |                 if (solve(l + r >> 1)) {
      |                           ~~^~~
sorting.cpp:36:33: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |                         res = l + r >> 1;
      |                               ~~^~~
sorting.cpp:37:32: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   37 |                         r = (l + r >> 1) - 1;
      |                              ~~^~~
sorting.cpp:39:32: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   39 |                         l = (l + r >> 1) + 1;
      |                              ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 300 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 1 ms 296 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Incorrect 1 ms 212 KB Output isn't correct
7 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 1 ms 296 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Incorrect 1 ms 212 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 436 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
3 Incorrect 2 ms 468 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 436 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
3 Incorrect 2 ms 468 KB Output isn't correct
4 Halted 0 ms 0 KB -