Submission #1075229

# Submission time Handle Problem Language Result Execution time Memory
1075229 2024-08-25T20:57:46 Z ArthuroWich Sorting (IOI15_sorting) C++17
20 / 100
37 ms 592 KB
#include "sorting.h"
#include<bits/stdc++.h>
using namespace std;
vector<pair<int, int>> ans, xy, swaps;
bool check(vector<int> p, int x, int n) {
    int s = 0;
    vector<int> e = p;
    vector<int> co(n, 0);
    for (int i = 0; i < n; i++) {
        co[i] = i;
    }
    for (int i = 0; i < x; i++) {
        swap(p[xy[i].first], p[xy[i].second]);
        swap(co[xy[i].first], co[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({i, j});
            swap(p[i], p[j]);
            s++;
        }
    }
    for (auto &x : swaps) {
        x.first = co[x.first];
        x.second = co[x.second];
    }
    while(swaps.size() < x) {
        swaps.push_back({0, 0});
    }
    return s <= x;
}
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]});
    }
    for (int i = 0; i <= M; i++) {
        swaps.clear();
        if (check(p, i, n)) {
            ans = swaps;
            break;
        }
    }
    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:27:16: warning: declaration of 'auto& x' shadows a parameter [-Wshadow]
   27 |     for (auto &x : swaps) {
      |                ^
sorting.cpp:5:31: note: shadowed declaration is here
    5 | bool check(vector<int> p, int x, int n) {
      |                           ~~~~^
sorting.cpp:31: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]
   31 |     while(swaps.size() < x) {
      |           ~~~~~~~~~~~~~^~~
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:51: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]
   51 |     for (int i = 0; i < ans.size(); i++) {
      |                     ~~^~~~~~~~~~~~
sorting.cpp:55:20: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   55 |     return ans.size();
      |            ~~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Incorrect 0 ms 348 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 592 KB Output isn't correct
2 Halted 0 ms 0 KB -