# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
568615 | urosk | Sorting (IOI15_sorting) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "sorting.h"
#define here cerr<<"===========================================\n"
#include <bits/stdc++.h>
#define ld double
#define ll int
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
using namespace std;
#define maxn 105
ll n,m;
ll a[maxn];
ll p[maxn];
bool sorted(){
for(ll i = 1;i<n;i++) if(a[i]>a[i+1]) return 0;
return 1;
}
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
n = N;
m = M;
for(ll i = 1;i<=n;i++) a[i] = S[i-1]+1;
for(ll i = 1;i<=n;i++) p[a[i]] = i;
ll sum = 0;
for(ll i = 0;i<m;i++) sum+=X[i] + Y[i];
ceri(a,1,n);
if(sum==0){
for(ll i = 1;i<=n;i++){
if(sorted()) return i-1;
P[i-1] = i-1;
Q[i-1] = p[i]-1;
ll x = a[i];
a[p[i]] = a[i];
a[i] = i;
swap(p[i],p[x]);
}
return n;
}
ll i = 1;
P[i-1] = i-1;
Q[i-1] = p[i]-1;
ll x = a[i];
a[p[i]] = a[i];
a[i] = i;
swap(p[i],p[x]);
swap(p[a[0]],p[a[1]]);
swap(a[0],a[1]);
i = 2;
P[i-1] = i-1;
Q[i-1] = p[i]-1;
ll x = a[0];
a[p[i]] = a[0];
a[i] = 1;
swap(p[i],p[x]);
swap(p[a[0]],p[a[1]]);
swap(a[0],a[1]);
for(ll i = 3;i<=n;i++){
if(sorted()) return i-1;
P[i-1] = i-1;
Q[i-1] = p[i]-1;
ll x = a[i];
a[p[i]] = a[i];
a[i] = i;
swap(p[i],p[x]);
swap(a[0],a[1]);
}
if(sorted()) return n;
P[n] = 0;
Q[n] = 0;
return n+1;
}