# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
288369 | shayan_p | 정렬하기 (IOI15_sorting) | C++17 | 370 ms | 14232 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "sorting.h"
#define F first
#define S second
#define PB push_back
#define sz(s) (int(s.size()))
#define bit(n, k) (((n)>>(k))&1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
const int maxn = 6e5 + 10, mod = 1e9 + 7;
bool mark[maxn];
int _p[maxn];
int findSwapPairs(int n, int p[], int q, int a[], int b[], int A[], int B[]){
fill(A, A + q, 0);
fill(B, B + q, 0);
for(int i = 0; i < n; i++){
_p[ p[i] ] = i;
}
auto Swap = [&](int i, int j){
swap(p[i], p[j]);
_p[ p[i] ] = i, _p[ p[j] ] = j;
};
auto need = [&](){
fill(mark, mark + n, 0);
int cnt = 0;
for(int i = 0; i < n; i++){
int tmp = i;
if(!mark[i]){
cnt++;
while(!mark[tmp]){
mark[tmp] = 1;
tmp = p[tmp];
}
}
}
return n - cnt;
};
auto calc_bin = [&](int q){
for(int i = 0; i < q; i++)
Swap(a[i], b[i]);
int x = need();
for(int i = q-1; i >= 0; i--)
Swap(a[i], b[i]);
return x <= q;
};
auto solve = [&](int q){
fill(mark, mark + n, 0);
vector<pii> tdo;
for(int i = 0; i < n; i++){
int tmp = i;
if(!mark[i]){
int SZ = sz(tdo);
while(!mark[tmp]){
if(i != tmp)
tdo.PB({i, tmp});
mark[tmp] = 1;
tmp = p[tmp];
}
reverse(tdo.begin() + SZ, tdo.end());
}
}
while(sz(tdo)){
q--;
int x = tdo.back().F, y = tdo.back().S;
tdo.pop_back();
A[q] = _p[x], B[q] = _p[y];
Swap(A[q], B[q]);
Swap(a[q], b[q]);
}
};
int l = -1, r = q;
while(r-l > 1){
int mid = (l+r) >> 1;
if(calc_bin(mid))
r = mid;
else
l = mid;
}
for(int i = 0; i < r; i++){
Swap(a[i], b[i]);
}
solve(r);
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... |