# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
544229 | timreizin | 정렬하기 (IOI15_sorting) | C++17 | 1 ms | 468 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "sorting.h"
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
bool check(int m, vector<int> s, vector<pair<int, int>> &swaps)
{
for_each(swaps.begin(), swaps.begin() + m, [&s](auto i){ swap(s[i.first], s[i.second]); });
int res = 0;
for (int i = 0; i < s.size(); ++i)
{
if (s[i] == i) continue;
++res;
swap(s[i], s[s[i]]);
}
return res <= m;
}
int findSwapPairs(int n, int S[], int m, int X[], int Y[], int P[], int Q[])
{
vector<int> s(n);
for (int i = 0; i < n; ++i) s[i] = S[i];
vector<pair<int, int>> swaps(m);
for (int i = 0; i < m; ++i)
{
swaps[i].first = X[i];
swaps[i].second = Y[i];
}
int l = 0, r = m;
while (l < r)
{
int m = (l + r) >> 1;
if (check(m, s, swaps)) r = m;
else l = m + 1;
}
//l - res
//cout << l;
vector<int> finish = s;
for_each(swaps.begin(), swaps.begin() + l, [&s = finish](auto i){ swap(s[i.first], s[i.second]); });
vector<int> pos(n);
for (int i = 0; i < n; ++i) pos[s[i]] = i;
for (int i = 0, j = 0; j < l; ++i)
{
if (i == n)
{
P[l - 1] = 0;
Q[l - 1] = 0;
break;
}
//if in the end and j != l add (0, 0)
if (finish[i] == i) continue;
swap(pos[s[swaps[j].first]], pos[s[swaps[j].second]]);
swap(s[swaps[j].first], s[swaps[j].second]);
//a = finish[i], b = finish[finish[i]]
int a = finish[i];
int b = finish[a];
swap(finish[i], finish[a]);
P[j] = pos[a];
Q[j] = pos[b];
swap(s[pos[a]], s[pos[b]]);
swap(pos[a], pos[b]);
++j;
}
return l;
}
컴파일 시 표준 에러 (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... |