# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
314190 | ShiftyBlock | Arranging Shoes (IOI19_shoes) | C++14 | 0 ms | 0 KiB |
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 <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pii pair<int, int>
#define long long long
#define v vector
#define rep(i,a,b) for(int i=a; i<b; i++)
void setIO(string name, int submit) {
if (submit) {
ios_base::sync_with_stdio(0);
cin.tie(0);
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
else{
ios_base::sync_with_stdio(0);
cin.tie(0);
}
}
int N;
int main() {
setIO("", 0);
cin>>N;
int arr[N];
for (int i = 0; i < N; ++i)
{cin>>arr[i]; }
int total=0;
for (int i = 0; i < N; ++i)
{
if(arr[i]==0) continue;
int free=0;
int end=-1;
rep(j,i+1,N){
if(arr[j]==-arr[i]){
end=j; break;
}
if(arr[j]==0) free++;
}
arr[end]=0;
if(arr[i]<0) total--;
total+=end-i;
}
cout<<total<<endl;
return 0;
}