| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 797242 | Ronin13 | 정렬하기 (IOI15_sorting) | C++17 | 140 ms | 21764 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "sorting.h"
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
int findSwapPairs(int n, int s[], int m, int x[], int y[], int P[], int Q[]) {
int l = -1, r = m;
while(l + 1 < r){
int mid = (l + r) / 2;
int b[n];
for(int i = 0; i < n; i++){
b[i] = s[i];
}
for(int i = 0; i < mid; i++){
swap(b[x[i]], b[y[i]]);
}
int pos[n];
int p[n];
for(int i = 0; i < n; i++){
pos[s[i]] = i;
p[b[i]] = i;
}
int a[n];
for(int i = 0; i < n; i++){
a[i] = s[i];;
}
int ind = 0;
for(int i = 0; i < mid; i++){
swap(pos[a[x[i]]], pos[a[y[i]]]);
swap(a[x[i]], a[y[i]]);
while(ind < n && b[ind] == ind) ind++;
if(ind == n) continue;
int x = b[ind];
swap(b[ind], b[p[ind]]);
swap(p[x], p[ind]);
swap(pos[x], pos[ind]);
swap(a[pos[x]], a[pos[ind]]);
}
bool good = true;
for(int i = 0; i < n; i++){
if(a[i] != i) good = false;
}
good ? r = mid : l = mid;
}
int b[n];
for(int i = 0; i < n; i++){
b[i] = s[i];
}
int p[n];
for(int i = 0; i < r; i++){
swap(b[x[i]], b[y[i]]);
}
int pos[n];
for(int i = 0; i < n; i++){
pos[s[i]] = i;
p[b[i]] = i;
}
int a[n];
for(int i = 0; i < n; i++){
a[i] = s[i];;
}
int ind = 0;
for(int i = 0; i < r; i++){
swap(pos[a[x[i]]], pos[a[y[i]]]);
swap(a[x[i]], a[y[i]]);
while(ind < n && b[ind] == ind) ind++;
if(ind == n) {
P[i] = Q[i] = 0;
continue;
}
int x = b[ind];
swap(b[ind], b[p[ind]]);
swap(p[x], p[ind]);
P[i] = pos[x], Q[i] = pos[ind];
swap(pos[x], pos[ind]);
swap(a[pos[x]], a[pos[ind]]);
}
bool good = true;
for(int i = 0; i < n; i++){
if(a[i] != i) good = false;
}
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... | ||||
