# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
257144 | eohomegrownapps | 정렬하기 (IOI15_sorting) | C++14 | 558 ms | 83448 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
struct SwapList{
vector<int> index;
vector<int> arr;
int n;
SwapList(int _n){
n=_n;
index.resize(n);
arr.resize(n);
}
void set(int ind, int val){
arr[ind]=val;
index[val]=ind;
}
int get(int ind){
return arr[ind];
}
int indexOf(int ind){
return index[ind];
}
void swapIndices(int a, int b){
swap(arr[a],arr[b]);
swap(index[arr[a]],index[arr[b]]);
}
void swapValues(int a, int b){
swapIndices(indexOf(a), indexOf(b));
}
};
int n;
int *x, *y, *s, *p, *q;
bool success(int m){
SwapList *nums = new SwapList(n);
SwapList *current = new SwapList(n);
for (int i = 0; i<n; i++){
nums->set(i,i);
current->set(i,s[i]);
}
for (int i = m-1; i>=0; i--){
nums->swapIndices(x[i],y[i]);
}
int curel = 0;
for (int i = 0; i<m; i++){
//perform opponent's swap
current->swapIndices(x[i],y[i]);
nums->swapIndices(x[i],y[i]);
//which to move?
while (curel<n&¤t->indexOf(curel)==nums->indexOf(curel)){
curel++;
}
if (curel==n){
for (int j = i; j<m; j++){
p[i]=0;
q[i]=0;
}
return true;
}
//indices to swap:
int curel_pos_current = current->indexOf(curel);
int curel_pos_nums = nums->indexOf(curel);
p[i]=curel_pos_current;
q[i]=curel_pos_nums;
current->swapIndices(curel_pos_current,curel_pos_nums);
/*for (int i = 0; i<n; i++){
cout<<current->get(i)<<' ';
}cout<<'\n';*/
}
for (int i = 0; i<n; i++){
if (current->get(i)!=i){return false;}
}
return true;
}
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
n=N;x=X;y=Y;s=S;p=P;q=Q;
int l = 0, r = M;
while (l<=r){
int mid = (l+r)/2;
bool s = success(mid);
//cout<<mid<<' '<<s<<'\n';
if (s){
r=mid-1;
} else {
l=mid+1;
}
}
//l is correct value
success(l);
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... |