Submission #623611

#TimeUsernameProblemLanguageResultExecution timeMemory
623611rubdaryArranging Shoes (IOI19_shoes)C++14
10 / 100
1 ms304 KiB
#include "shoes.h" #include <iostream> #include <vector> #include <algorithm> #include <utility> #include <queue> using namespace std; vector <pair <int, int>> n, p; vector <queue <int>> izq, derc; vector <bool> vis; int res = 0, x; long long count_swaps(vector <int> s){ int N = s.size()/2; for(int 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(); res += x - i - 1; }else{ x = izq[s[i]].front(); izq[s[i]].pop(); derc[s[i]].pop(); res += x - i; } vis[x] = true; vis[i] = true; } return res; }
#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...