제출 #690964

#제출 시각아이디문제언어결과실행 시간메모리
690964finn__Arranging Shoes (IOI19_shoes)C++17
10 / 100
1 ms260 KiB
#include <bits/stdc++.h> using namespace std; #include "shoes.h" long long count_swaps(vector<int> s) { size_t const n = s.size(); vector<bool> processed(n, 0); vector<priority_queue<unsigned, vector<unsigned>, greater<unsigned>>> q(n); for (unsigned i = 0; i < n; i++) q[2 * (abs(s[i]) - 1) + (s[i] < 0)].push(i); long long swaps_needed = 0; for (unsigned i = 0; i < n; i++) { if (!processed[i]) { processed[i] = 1; while (processed[q[2 * (abs(s[i]) - 1) + (s[i] > 0)].top()]) q[2 * (abs(s[i]) - 1) + (s[i] > 0)].pop(); unsigned j = q[2 * (abs(s[i]) - 1) + (s[i] > 0)].top(); q[2 * (abs(s[i]) - 1) + (s[i] > 0)].pop(); processed[j] = 1; swaps_needed += j - i - (s[i] < 0); } } return swaps_needed; }
#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...