# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
108756 | PeppaPig | 정렬하기 (IOI15_sorting) | C++14 | 338 ms | 21676 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "sorting.h"
#include <bits/stdc++.h>
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const int N = 2e5+5;
int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]) {
auto solve = [&](int k) {
vector<int> v(s, s + n), pos(n);
vector<pii> ret;
for(int i = 0; i < k; i++) swap(v[x[i]], v[y[i]]);
for(int i = 0; i < n; i++) pos[v[i]] = i;
for(int i = 0; i < n; i++) if(v[i] != i) {
ret.emplace_back(v[i], i);
int now = v[i];
swap(v[i], v[pos[i]]);
swap(pos[now], pos[i]);
}
return ret;
};
int l = 0, r = m;
while(l < r) {
int mid = (l + r) >> 1;
if(solve(mid).size() <= mid) r = mid;
else l = mid+1;
}
vector<pii> ans = solve(r);
vector<int> pos(n);
for(int i = 0; i < n; i++) pos[s[i]] = i;
for(int i = 0; i < r; i++) {
swap(pos[s[x[i]]], pos[s[y[i]]]);
swap(s[x[i]], s[y[i]]);
if(i < ans.size()) {
int a, b; tie(a, b) = ans[i];
p[i] = pos[a], q[i] = pos[b];
swap(s[pos[a]], s[pos[b]]);
swap(pos[a], pos[b]);
}
}
for(int i = ans.size(); i < r; i++) p[i] = 0, q[i] = 0;
return r;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |