제출 #301931

#제출 시각아이디문제언어결과실행 시간메모리
301931NicolaAbusaad2014Arranging Shoes (IOI19_shoes)C++14
45 / 100
39 ms6132 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; long long count_swaps(std::vector<int> s) { long n=s.size(); vector<long>left; vector<long>right; bool ok[n]={}; long now=0,arr[n]={},x=0,z,ans=0; for(long i=0;i<n;i++){ if(s[i]<0){ left.push_back(i); } else{ right.push_back(i); } } for(long i=0;i<n;i++){ x+=arr[i]; if(!ok[i]){ if(s[i]<0){ z=right[now]; ok[right[now]]=true; now++; arr[i+1]++; arr[z]--; ans+=z-x-i-1; } else{ ans++; z=left[now]; ok[left[now]]=true; now++; arr[i+1]++; arr[z]--; ans+=z-x-i-1; } } } return ans; }
#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...