답안 #1075255

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1075255 2024-08-25T21:38:05 Z ArthuroWich 정렬하기 (IOI15_sorting) C++17
16 / 100
1 ms 604 KB
#include "sorting.h"
#include<bits/stdc++.h>
using namespace std;
vector<pair<int, int>> ans, xy, swaps;
bool check(vector<int> p, int m, int n) {
    int s = 0;
    vector<int> e = p;
    vector<int> co(n, 0);
    for (int i = 0; i < n; i++) {
        co[p[i]] = i;
    }
    for (int i = 0; i < m; i++) {
        swap(p[xy[i].first], p[xy[i].second]);
    }
    for (int i = 0; i < n; i++) {
        if (p[i] == i) {
            continue;
        }
        while(p[i] != i) {
            int j = p[i];
            swaps.push_back({p[i], p[j]});
            swap(p[i], p[j]);
            s++;
        }
    }
    if (swaps.size() > m) {
        return 0;
    }
    while(swaps.size() < m) {
        swaps.push_back({0, 0});
    }
    for (int i = 0; i < m; i++) {
        swap(co[e[xy[i].first]], co[e[xy[i].second]]);
        swap(e[xy[i].first], e[xy[i].second]);
        auto [x, y] = swaps[i];
        swaps[i] = {co[x], co[y]};
        swap(e[co[x]], e[co[y]]);
        swap(co[x], co[y]);
    }
    return s <= m;
}
int findSwapPairs(int n, int A[], int M, int X[], int Y[], int P[], int Q[]) {
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        p[i] = A[i];
    }
    for (int i = 0; i < M; i++) {
        xy.push_back({X[i], Y[i]});
    }
    check(p, M, n);
    ans = swaps;
    for (int i = 0; i < ans.size(); i++) {
        P[i] = ans[i].first;
        Q[i] = ans[i].second;
    }
    return ans.size();
}

Compilation message

sorting.cpp: In function 'bool check(std::vector<int>, int, int)':
sorting.cpp:26:22: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   26 |     if (swaps.size() > m) {
      |         ~~~~~~~~~~~~~^~~
sorting.cpp:29:24: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   29 |     while(swaps.size() < m) {
      |           ~~~~~~~~~~~~~^~~
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:52:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for (int i = 0; i < ans.size(); i++) {
      |                     ~~^~~~~~~~~~~~
sorting.cpp:56:20: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   56 |     return ans.size();
      |            ~~~~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -