제출 #669709

#제출 시각아이디문제언어결과실행 시간메모리
669709victor_gaoSorting (IOI15_sorting)C++17
54 / 100
96 ms468 KiB
#include "sorting.h" #include <bits/stdc++.h> #define MAXN 200015 using namespace std; int bk[MAXN],pos_bk[MAXN],pre[MAXN],pos_pre[MAXN]; int solve(int N,int n,int S[],int P[],int Q[],int X[],int Y[]){ for (int i=0;i<N;i++){ bk[i]=i; pos_bk[i]=i; pre[i]=S[i]; pos_pre[S[i]]=i; } for (int i=n-1;i>=0;i--){ swap(bk[X[i]],bk[Y[i]]); pos_bk[bk[X[i]]]=X[i]; pos_bk[bk[Y[i]]]=Y[i]; } for (int i=0;i<n;i++){ bool flag=1; for (int j=0;j<N;j++){ if (pre[j]!=j){ flag=0; break; } } if (flag) return i; swap(pre[X[i]],pre[Y[i]]); pos_pre[pre[X[i]]]=X[i]; pos_pre[pre[Y[i]]]=Y[i]; swap(bk[X[i]],bk[Y[i]]); pos_bk[bk[X[i]]]=X[i]; pos_bk[bk[Y[i]]]=Y[i]; int now=i+1; P[i]=pos_pre[now]; Q[i]=pos_bk[now]; swap(pre[pos_pre[now]],pre[pos_bk[now]]); pos_pre[pre[pos_pre[now]]]=pos_pre[now]; pos_pre[pre[pos_bk[now]]]=pos_bk[now]; } bool flag=1; for (int i=0;i<N;i++){ if (pre[i]!=i) flag=0; } if (flag) return n; else return 1e9; } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { int mn=1e9,pos; for (int i=0;i<N+1;i++){ int need=solve(N,i,S,P,Q,X,Y); if (need<mn){ mn=need; pos=i; } } return solve(N,pos,S,P,Q,X,Y); }

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

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:45:39: warning: unused parameter 'M' [-Wunused-parameter]
   45 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                   ~~~~^
sorting.cpp:54:17: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   54 |     return solve(N,pos,S,P,Q,X,Y);
      |            ~~~~~^~~~~~~~~~~~~~~~~
#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...