Submission #172177

#TimeUsernameProblemLanguageResultExecution timeMemory
172177dsjongArranging Shoes (IOI19_shoes)C++14
50 / 100
1081 ms3196 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; long long count_swaps(vector<int> s) { int n=s.size(); int cnt=0; for(int i=0;i<n;i++){ if((i%2==0&&s[i]+s[i+1]==0&&s[i]<0)||(i%2==1&&s[i]+s[i-1]==0&&s[i]>0)) continue; //cout<<i<<endl; if(s[i]<0){ for(int j=0;j<n;j++){ if(s[j]+s[i]==0&&!(s[j]+s[j-1]==0&&j<i)){ int cur=j; if(cur==i+1) break; if(cur>i){ while(cur!=i+1){ swap(s[cur],s[cur-1]); //cout<<cur<<" "<<cur-1<<endl; cur--; cnt++; } } else{ while(cur!=i){ swap(s[cur],s[cur+1]); //cout<<cur<<" "<<cur+1<<endl; cur++; cnt++; } } break; } } } else{ for(int j=0;j<n;j++){ if(s[j]+s[i]==0&&!(s[j]+s[j+1]==0&&j<i)){ int cur=j; if(cur==i-1) break; if(cur>i){ while(cur!=i){ swap(s[cur],s[cur-1]); //cout<<cur<<" "<<cur-1<<endl; cur--; cnt++; } } else{ while(cur!=i+1){ swap(s[cur],s[cur+1]); //cout<<cur<<" "<<cur+1<<endl; cur++; cnt++; } } break; } } } } return cnt; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...