Submission #623951

#TimeUsernameProblemLanguageResultExecution timeMemory
623951rubdaryArranging Shoes (IOI19_shoes)C++14
10 / 100
1 ms296 KiB
#include "shoes.h" #include <iostream> #include <vector> #include <algorithm> #include <utility> #include <queue> #define ll long long using namespace std; vector <pair <ll, ll>> n, p; vector <queue <ll>> izq, derc; vector <bool> vis; ll ans = 0, x; long long count_swaps(vector <int> s){ int N = s.size()/2; for(ll i = 0; i < 2*N; i++){ if(s[i] < 0) n.push_back({s[i] * (-1), i}); if(s[i] > 0) p.push_back({s[i], i}); } sort(n.begin(), n.end()); sort(p.begin(), p.end()); izq.resize(N+1); derc.resize(N+1); for(int i = 0; i < N; i++){ izq[n[i].first].push(n[i].second); derc[p[i].first].push(p[i].second); } for(int i = 0; i < 2*N+1; i++) vis.push_back(false); for(int i = 0; i < 2*N; i++){ if(vis[i] == true) continue; if(s[i] < 0){ x = derc[s[i] * (-1)].front(); derc[s[i] * (-1)].pop(); izq[s[i] * (-1)].pop(); ans += x - i - 1; }else{ x = izq[s[i]].front(); izq[s[i]].pop(); derc[s[i]].pop(); ans += x - i; } vis[x] = true; vis[i] = true; } 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...