Submission #1075184

#TimeUsernameProblemLanguageResultExecution timeMemory
1075184ArthuroWichSorting (IOI15_sorting)C++17
0 / 100
1 ms600 KiB
#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; for (int i = 0; i < x; 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({i, j}); swap(p[i], p[j]); s++; } } while(swaps.size() < x) { swaps.push_back({1, 1}); } return s <= x; } int findSwapPairs(int n, int A[], int M, int X[], int Y[], int P[], int Q[]) { vector<pair<int, int>> ans; 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 (stderr)

sorting.cpp: In function 'bool check(std::vector<int>, int, int)':
sorting.cpp:21: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]
   21 |     while(swaps.size() < x) {
      |           ~~~~~~~~~~~~~^~~
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:27:28: warning: declaration of 'ans' shadows a global declaration [-Wshadow]
   27 |     vector<pair<int, int>> ans;
      |                            ^~~
sorting.cpp:4:24: note: shadowed declaration is here
    4 | vector<pair<int, int>> ans, xy, swaps;
      |                        ^~~
sorting.cpp:37: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]
   37 |     for (int i = 0; i < ans.size(); i++) {
      |                     ~~^~~~~~~~~~~~
sorting.cpp:41:20: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   41 |     return ans.size();
      |            ~~~~~~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...