제출 #314618

#제출 시각아이디문제언어결과실행 시간메모리
314618amunduzbaevSorting (IOI15_sorting)C++14
0 / 100
2 ms768 KiB
//#include "grader.cpp" #include "sorting.h" #include <bits/stdc++.h> using namespace std; const int N=2*1e5+5; int n, s[N], x[N], y[N]; vector<pair<int,int>>ans; bool check(int m){ int a[N], pos[N]; for(int i=0;i<n;i++) a[i]=s[i]; for(int i=0;i<m;i++) swap(a[x[i]], a[y[i]]); for(int i=0;i<n;i++) pos[a[i]]=i; vector<pair<int,int > > swaps; for(int i=0;i<n;i++){ if(pos[i]!=i){ int j=pos[i]; swaps.push_back({a[i],a[j]}); pos[a[i]]=j; swap(a[i],a[j]); } } if(swaps.size()>m) return false; ans.clear(); /* cout<<m<<"\n"; for(int i=0;i<swaps.size();i++){ cout<<swaps[i].first<<" "<<swaps[i].second<<"\n"; } */ for(int i=0;i<n;i++) a[i]=s[i], pos[a[i]]=i; for(int i=0;i<swaps.size();i++){ int x1=x[i], y1=y[i], i1=swaps[i].first, j1=swaps[i].second; ans[i] = {pos[i1],pos[j1]}; i1=pos[i1],j1=pos[j1]; swap ( a[x1] ,a[y1] ); swap ( a[i1], a[j1] ); swap ( pos[a[x1]], pos[a[y1]] ); swap ( pos[a[i1]], pos[a[j1]] ); } for(int i=swaps.size(); i<m; i++) ans.push_back({0,0}); return true; } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { n=N; for(int i=0;i<n;i++) s[i]=S[i]; for(int i=0;i<M;i++) x[i]=X[i], y[i]=Y[i]; int l=0,r=M; while(l<r){ int md=(l+r)/2; if(check(md)) r=md; else l=md+1; } for(int i=0;i<ans.size();i++){ P[i]=ans[i].first; Q[i]=ans[i].second; } return l; }

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

sorting.cpp: In function 'bool check(int)':
sorting.cpp:25:20: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |     if(swaps.size()>m) return false;
      |        ~~~~~~~~~~~~^~
sorting.cpp:34:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int i=0;i<swaps.size();i++){
      |                 ~^~~~~~~~~~~~~
sorting.cpp:43:25: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   43 |     for(int i=swaps.size(); i<m; i++)
      |               ~~~~~~~~~~^~
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:48:76: warning: declaration of 'N' shadows a global declaration [-Wshadow]
   48 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                                                            ^
sorting.cpp:5:11: note: shadowed declaration is here
    5 | const int N=2*1e5+5;
      |           ^
sorting.cpp:58:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for(int i=0;i<ans.size();i++){
      |                 ~^~~~~~~~~~~
#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...