# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
169275 | anubhavdhar | Arranging Shoes (IOI19_shoes) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,N) for(i=0;i<N;i++)
#define FORe(i,N) for(i=1;i<=N;i++)
#define FORr(i,a,b) for(i=a;i<b;i++)
#define ii pair<ll,ll>
#define vi vector<ll>
#define vii vector<ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
using namespace std;
#include "shoes.h"
const ll MAXN = 1e5+5;
const ll INF = 1e17 + 9;
const ll MOD = 1e9 + 7;
const ll INT_BITS = 31;
const ll LOGN = 17;
long long count_swaps(vector<int>s)
{
//cout<<"p\n";
ll N,i,j,l,r,ans = 0;
//cin>>N;
N = s.size()*2;
ll A[N],pr[N];
queue<ll> L[MAXN],R[MAXN];
bool rem[N];
FOR(i,N)
{
A[i] = s[i];
//cout<<"entering for i = "<<i<<endl;
rem[i] = false;
if (A[i] < 0) // Left shoe
{
if (!R[-A[i]].empty())
{
r = R[-A[i]].front();
R[-A[i]].pop();
pr[r] = i;
pr[i] = r;
A[i] *= -1;
A[r] *= -1;
ans++;
}
else
L[-A[i]].push(i);
}
else if (A[i] > 0) // Right Shoe;
{
if (!L[A[i]].empty())
{
l = L[A[i]].front();
L[A[i]].pop();
pr[l] = i;
pr[i] = l;
}
else
R[A[i]].push(i);
}
}
/*
FOR(i,N)
cout<<A[i]<<" ";
cout<<endl;
FOR(i,N)
cout<<pr[i]<<" ";
cout<<endl;
*/
FOR(i,N)
{
if(A[i] < 0)
{
ans += pr[i]-i-1;
for(j = i + 1;j<pr[i];j++)
if (rem[j])
ans--;
rem[pr[i]] = true;
}
}
return ans;
}