이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "sorting.h"
using namespace std;
const int MXN = 2e5 + 100;
int n, m, a[MXN], p[MXN], pos[MXN], tmp[MXN], pos_box[MXN];
bool is_sorted(){
bool good = 1;
for (int i = 1; i < n; i ++)
good &= (a[i] >= a[i - 1]);
return good;
}
int findSwapPairs(int N, int s[], int M, int x[], int y[], int rx[], int ry[]){
n = N, m = M;
for (int i = 0; i < n; i ++)
a[i] = s[i];
if (is_sorted())
return 0;
int l = 0;
int r = n;
while (r - l > 1){
int mid = (l + r) / 2;
for (int i = 0; i < n; i ++)
p[i] = tmp[i] = i, a[i] = s[i], pos[a[i]] = i, pos_box[i] = i;
for (int i = 0; i < mid; i ++)
swap(p[x[i]], p[y[i]]);
int steps = 0;
bool move = 0;
for (int i = 0, j = 0; i < n and j < mid;){
if (!move){
swap(pos_box[tmp[x[j]]], pos_box[tmp[y[j]]]);
swap(tmp[x[j]], tmp[y[j]]);
swap(pos[a[x[j]]], pos[a[y[j]]]);
swap(a[x[j]], a[y[j]]);
move = 1;
continue;
}
if (pos[i] == pos_box[p[i]]){
i++;
continue;
}
move = 0;
rx[j] = pos[i], ry[j] = pos_box[p[i]];
swap(pos[i], pos[a[ry[j]]]);
swap(a[rx[j]], a[ry[j]]);
i++;
j++;
}
if (is_sorted())
r = mid;
else
l = mid;
}
return r;
}
컴파일 시 표준 에러 (stderr) 메시지
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:34:13: warning: unused variable 'steps' [-Wunused-variable]
34 | int steps = 0;
| ^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |