# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
973995 | PagodePaiva | 정렬하기 (IOI15_sorting) | C++17 | 7 ms | 620 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "sorting.h"
using namespace std;
int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]) {
int pai[n];
for(int i = 0;i < n;i++){
pai[s[i]] = i;
}
bool aux = true;
for(int i = 1;i < n;i++){
if(s[i] < s[i-1]) aux = false;
}
if(aux){
return 0;
}
int l = 0, r = m-1;
int resp = -1;
while(l <= r){
int mid = (l+r)>>1;
int paimid[n];
int mark[n];
for(int i = 0;i < n;i++) {
paimid[i] = pai[i];
mark[i] = false;
}
for(int i = l;i <= mid;i++){
swap(paimid[x[i]], paimid[y[i]]);
}
int res = 0;
for(int i = 0;i < n;i++){
if(mark[i]) continue;
int x = i;
while(!mark[x]){
res++;
mark[x] = true;
x = paimid[x];
}
res--;
}
if(res <= mid+1){
r = mid-1;
resp = mid;
}
else{
for(int i = 0;i < n;i++) pai[i] = paimid[i];
l = mid+1;
}
}
// cout << resp << '\n';
for(int i = 0;i < m;i++) p[i] = q[i] = 0;
vector <int> v;
for(int i = 0;i < n;i++){
v.push_back(i);
}
for(int i = resp;i >= 0;i--){
swap(v[x[i]], v[y[i]]);
}
int at = 0;
for(int i = 0;i <= resp;i++){
bool aux = true;
for(int j = 1;j < n;j++){
if(s[j] < s[j-1]) aux = false;
}
if(aux) break;
swap(v[x[i]], v[y[i]]);
swap(s[x[i]], s[y[i]]);
int poss, posv;
while(true){
if(at == n){
p[i] = 0;
q[i] = 0;
return i+1;
}
for(int j = 0;j < n;j++){
if(s[j] == at) poss = j;
if(v[j] == at) posv = j;
}
if(poss == posv){
at++;
continue;
}
// cout << poss << ' ' << posv << '\n';
p[i] = poss;
q[i] = posv;
at++;
break;
}
swap(s[poss], s[posv]);
if(at == n){
// for(int j = 0;j <= i;j++) cout << p[j] << ' ' << q[j] << "\n";
return i+1;
}
while(true){
if(at == n){
// for(int j = 0;j <= i;j++) cout << p[j] << ' ' << q[j] << "\n";
return i+1;
}
int poss, posv;
for(int j = 0;j < n;j++){
if(s[j] == at) poss = j;
if(v[j] == at) posv = j;
}
if(poss == posv){
at++;
continue;
}
break;
}
}
// for(int j = 0;j <= resp;j++) cout << p[j] << ' ' << q[j] << "\n";
return resp+1;
}
컴파일 시 표준 에러 (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... |