이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define OYY LLONG_MAX
#define mod 1000000007
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define FOR for(int i=1;i<=n;i++)
#define mid (start+end)/2
#define lim 300005
#define fi first
#define se second
int n,cev,as_cev=INT_MAX;
vector<int> v;
int dizi[lim];
inline void brute(int sira,int mask){
//cout<<sira<<" "<<mask<<endl;
if(sira>n){
bool stop=1;
/*FOR{
cout<<dizi[i]<<" ";
}
cout<<endl<<endl;*/
FOR{
if(dizi[i]<0 && dizi[i]==-dizi[i+1]){i++;continue;}
stop=0;
break;
}
if(stop)as_cev=min(as_cev,cev);
return ;
}
FOR{
if(mask&(1<<(i-1)))continue;
int eski=dizi[sira];
dizi[sira]=v[i-1];
cev+=abs(sira-i);
brute(sira+1,mask|(1<<(i-1)));
cev-=abs(sira-i);
dizi[sira]=eski;
}
}
long long count_swaps(std::vector<int> s) {
n=s.size();
int tut=1;
for(auto x:s){
v.push_back(x);
dizi[tut++]=x;
}
//cout<<n<<" ppp"<<endl;
brute(1,0);
return as_cev/2;
}
/*
int main(){
//faster
int m;cin>>m;
vector<int> vv;
for(int i=1;i<=m;i++){
int x;cin>>x;
vv.push_back(x);
}
cout<<count_swaps(vv)<<'\n';
return 0;
}
*/
# | 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... |