제출 #1075239

#제출 시각아이디문제언어결과실행 시간메모리
1075239ArthuroWich정렬하기 (IOI15_sorting)C++17
0 / 100
56 ms656 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; 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 : p) { } 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++; } } for (auto &x : swaps) { x.first = e[co[x.first]]; x.second = e[co[x.second]]; swap(e[co[x.first]], e[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(); }

컴파일 시 표준 에러 (stderr) 메시지

sorting.cpp: In function 'bool check(std::vector<int>, int, int)':
sorting.cpp:16:14: warning: unused variable 'i' [-Wunused-variable]
   16 |     for (int i : p) {
      |              ^
sorting.cpp:30:16: warning: declaration of 'auto& x' shadows a parameter [-Wshadow]
   30 |     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:35: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]
   35 |     while(swaps.size() < x) {
      |           ~~~~~~~~~~~~~^~~
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:55: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]
   55 |     for (int i = 0; i < ans.size(); i++) {
      |                     ~~^~~~~~~~~~~~
sorting.cpp:59:20: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   59 |     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...