제출 #68651

#제출 시각아이디문제언어결과실행 시간메모리
68651MANcity정렬하기 (IOI15_sorting)C++14
0 / 100
6 ms2020 KiB
#include<iostream> #include<cstdio> #include<fstream> #include<algorithm> #include<cmath> #include<map> #include<queue> #include<set> #include<stack> #include<string> #include<cstring> #include<vector> #include "sorting.h" using namespace std; #define for1(i,n) for(int i=1;i<=(int)n;i++) #define for0(i,n) for(int i=0;i<=(int)n;i++) #define forn(i,n) for(int i=n;i>=1;i--) #define fo(i,x,y) for(int i=x;i<=(int)y;i++) #define fr(i,x,y) for(int i=x;i>=(int)y;i--) #define pb push_back #define mp make_pair #define LL long long const LL Mod=1000*1000*1000+7; int t[200002]; int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { int u=0; for0(i,N-1) if(S[i]!=i) u=1; if(u==0) return 0; int l=0; int r=(M-1); while(1) { if(l==r) { pair<int,int> NS[200002]; int pos[200002]; for0(i,N-1) NS[i]=mp(S[i],i); for0(i,l) { pair<int,int> t=NS[Y[i]]; NS[Y[i]]=NS[X[i]]; NS[X[i]]=t; } for0(i,N-1) pos[NS[i].first]=i; vector<pair<int,int> > ans; for0(i,N-1) { if(NS[i].first!=i) { int t=pos[i]; ans.push_back({NS[i].second,NS[t].second}); pos[NS[i].first]=t; pos[i]=i; pair<int,int> c=NS[t]; NS[t]=NS[i]; NS[i]=c; } } int H[200002]; pos[200002]; for0(i,N-1) { H[i]=i; pos[i]=i; } for0(i,l) { pos[H[Y[i]]]=X[i]; pos[H[X[i]]]=Y[i]; int t=H[Y[i]]; H[Y[i]]=H[X[i]]; H[X[i]]=t; P[i]=pos[ans[i].first]; Q[i]=pos[ans[i].second]; if(i>ans.size()-1) { P[i]=0; Q[i]=0; } } return (l+1); } int m=(l+r)/2; int NS[200002]; int pos[200002]; for0(i,N-1) NS[i]=S[i]; for0(i,m) { int p=NS[Y[i]]; NS[Y[i]]=NS[X[i]]; NS[X[i]]=p; } for0(i,N-1) pos[NS[i]]=i; int q=0; for0(i,N-1) { if(NS[i]!=i) { q++; NS[pos[i]]=NS[i]; pos[NS[i]]=pos[i]; NS[i]=i; pos[i]=i; } } if(q>(m+1)) l=(m+1); else r=m; } }

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

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:45:31: warning: declaration of 't' shadows a global declaration [-Wshadow]
                 pair<int,int> t=NS[Y[i]];
                               ^
sorting.cpp:24:5: note: shadowed declaration is here
 int t[200002];
     ^
sorting.cpp:56:25: warning: declaration of 't' shadows a global declaration [-Wshadow]
                     int t=pos[i];
                         ^
sorting.cpp:24:5: note: shadowed declaration is here
 int t[200002];
     ^
sorting.cpp:66:23: warning: statement has no effect [-Wunused-value]
             pos[200002];
             ~~~~~~~~~~^
sorting.cpp:76:21: warning: declaration of 't' shadows a global declaration [-Wshadow]
                 int t=H[Y[i]];
                     ^
sorting.cpp:24:5: note: shadowed declaration is here
 int t[200002];
     ^
sorting.cpp:81:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if(i>ans.size()-1)
                    ~^~~~~~~~~~~~~
#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...