//#include <GOD>
//kole shahr khakestary , bala sar man ranginkamon
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
#define pb push_back
#define len length
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define freo freopen("guard.out","w",stdout)
#define frei freopen("guard.in","r",stdin)
const ll inf=1e18+10;
const ll mod=1e9+7;
const ll maxn=(1e5)+10,maxm=1e5+10,sq=310+10,maxa=(1<<maxn),mlg=32;
bool cmp(pair<int,int> a,pair<int ,int > b){
return a.first+a.second < b.first+b.second;
}
int count_swaps(vector <int> S){
int n = S.size();
n/=2;
vector <int> ve[n+1][2];
for(int i=0;i<2*n;i++){
// cout<<i<<endl;
if(S[i]>0){
ve[abs(S[i])][1].pb(i);
}else{
ve[abs(S[i])][0].pb(i);
}
}
// cout<<n<<endl;
vector <pair<int,int>> tmp;
for(int i=1;i<=n;i++){
for(int j=0;j<2;j++){
sort(ve[i][j].begin(),ve[i][j].end());
}
for(int j=0;j<ve[i][0].size();j++){
tmp.pb({ve[i][0][j],ve[i][1][j]});
}
}
// cout<<n<<endl;
sort(tmp.begin(),tmp.end(),cmp);
int ans=0;
for(int i=0;i<tmp.size();i++){
ans+=abs(tmp[i].first-2*i)+abs(tmp[i].second+(tmp[i].first>tmp[i].second)-(2*i+1));
}
return ans;
}
// int main(){
// vector <int> arr1={2, 1, -1, -2};
// cout<<count_swaps(arr1)<<endl;
// vector <int> arr2={-2, 2, 2, -2, -2, 2};
// cout<<count_swaps(arr2)<<endl;
// }
컴파일 시 표준 에러 (stderr) 메시지
shoes.cpp:15:53: warning: left shift count >= width of type [-Wshift-count-overflow]
15 | const ll maxn=(1e5)+10,maxm=1e5+10,sq=310+10,maxa=(1<<maxn),mlg=32;
| ~^~~~~~
# | 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... |