# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
289840 | NicolaAbusaad2014 | Arranging Shoes (IOI19_shoes) | C++14 | 1 ms | 256 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 "shoes.h"
#include <bits/stdc++.h>
using namespace std;
long long count_swaps(vector<int> s) {
long long ans=0,z=0,dp[s.size()+1];
dp[0]=0;
map<long,vector<long> >m;
map<long,long>now,vis;
for(long i=0;i<s.size();i++){
vis[s[i]]++;
m[s[i]].push_back(i);
z++;
if(vis[s[i]]&&vis[-s[i]]){
if(s[i]<0){
ans+=m[s[i]][now[abs(s[i])]]-m[-s[i]][now[abs(s[i])]];
}
else{
ans+=m[s[i]][now[abs(s[i])]]-m[-s[i]][now[abs(s[i])]]-1;
}
ans+=m[s[i]][now[abs(s[i])]]-m[-s[i]][now[abs(s[i])]]-1;
ans-=dp[m[-s[i]][now[abs(s[i])]]]*2;
vis[s[i]]--;
vis[-s[i]]--;
now[abs(s[i])]++;
z-=2;
}
dp[i+1]=z;
}
return ans;
}
Compilation message (stderr)
# | 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... |