제출 #114697

#제출 시각아이디문제언어결과실행 시간메모리
114697arman_ferdous정렬하기 (IOI15_sorting)C++17
20 / 100
1068 ms512 KiB
#include "sorting.h" #include <bits/stdc++.h> using namespace std; const int N = 2e5+100; int n, ss[N], m, x[N], y[N], p[N], q[N]; int tmp[N]; int solve(int M) { for(int i = 0; i < n; i++) tmp[i] = ss[i]; for(int i = 0; i < M; i++) swap(tmp[x[i]], tmp[y[i]]); int cur = 0, R = 0; for(int i = 0; i < n; ) { if(tmp[i] == i) { i++; continue; } int pp = i, qq = tmp[i]; if(cur >= M) return -1; for(int j = M-1; j > cur; j--) { if((x[j] == pp && y[j] == qq) || (x[j] == qq && y[j] == pp)) swap(pp, qq); else { if(x[j] == pp) pp = y[j]; else if(y[j] == pp) pp = x[j]; if(x[j] == qq) qq = y[j]; else if(y[j] == qq) qq = x[j]; } } p[R] = pp, q[R] = qq; R++, cur++; swap(tmp[i], tmp[tmp[i]]); } return R; } int findSwapPairs(int _n, int S[], int M, int X[], int Y[], int P[], int Q[]) { n = _n, m = M; for(int i = 0; i < n; i++) ss[i] = S[i]; for(int i = 0; i < m; i++) x[i] = X[i], y[i] = Y[i]; // int lo = 0, hi = M, idx; // while(lo <= hi) { // int mid = (lo + hi) >> 1; // int R = solve(mid); // if(R == -1) lo = mid+1; // else idx = mid, hi = mid-1; // } for(int i = 0; i <= M; i++) if(solve(i) == i) { for(int j = 0; j < i; j++) P[j] = p[j], Q[j] = q[j]; return i; } // int R = solve(idx); // for(int i = 0; i < R; i++) // P[i] = p[i], Q[i] = q[i]; }

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

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:62:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#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...