This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "shoes.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define INF 1e9+7
#define all(x) x.begin(),x.end()
using namespace std;
using namespace __gnu_pbds;
using pii=pair<int,int>;
using ppi=pair<int,pii>;
using ll=long long;
using oset=tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;
void _print(vector<pii> x) {cerr<<"["; for(auto e:x) cerr<<"{"<<e.first<<","<<e.second<<"} ,"; cerr<<"]";}
template<typename T>
void _print(vector<T> x) {cerr<<"{"; for(auto e:x) cerr<<e<<","; cerr<<"}";}
void _print(pii x) {cerr<<"{"<<x.first<<","<<x.second<<"}";}
template<typename T>
void _print(T x) {cerr<<x;}
void dbg() {cerr<<endl;}
template<typename Head,typename... Tail>
void dbg(Head H,Tail... T) {
_print(H);
if(sizeof...(T)) cerr<<",";
else cerr<<"]";
dbg(T...);
}
#define debug(...) cerr<<"[\""<<#__VA_ARGS__<<"\"]: [",dbg(__VA_ARGS__);
long long count_swaps(std::vector<int> s) {
int n=s.size();
ll ans=0;
bool sub4=true;
for(int i=0;i<n;i++) {
if(s[i]==-s[i+n] and s[i]<0) continue;
sub4=false; break;
}
if(sub4) {
for(int i=1;i<n;i++) ans+=i;
return ans;
}
for(int i=0;i<n;i++) {
if(s[i]==-s[i^1]) {
if(i&1 and s[i]<0) ans++;
continue;
}
int r;
for(int j=i+1;j<n;j++) {
if(s[j]==-s[i]) {
r=j; break;
}
}
while(r>i+1) {
ans++; swap(s[r],s[r-1]); r--;
}
if(s[i]>0) swap(s[i],s[i+1]),ans++;
}
return ans;
}
Compilation message (stderr)
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:50:13: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
50 | int r;
| ^
# | 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... |