제출 #1034520

#제출 시각아이디문제언어결과실행 시간메모리
1034520enderArranging Shoes (IOI19_shoes)C++17
85 / 100
41 ms4396 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; long long count_swaps(std::vector<int> s) { if(s.size() > 2000){ long long ans = 0; priority_queue<int, vector<int>, greater<int>> l, r; for(int i = 0; i < (int)s.size(); ++i){ if(s[i] < 0) l.push(i); else r.push(i); } for(int i = 0; i < (int)s.size(); ++i){ if(i%2 == 0){ if(s[i] > 0){ ans += l.top() - i; swap(s[i], s[l.top()]); r.pop(); r.push(l.top()); } l.pop(); }else { if(s[i] < 0){ ans += r.top() - i; swap(s[i], s[r.top()]); l.pop(); l.push(r.top()); } r.pop(); } } return ans; } long long ans = 0; for(int i = 0; i < (int)s.size(); i += 2){ if(s[i] < 0){ for(int j = i+1; j < (int)s.size(); ++j){ if(s[j] == -s[i]){ for(int k = j; k > i+1; --k){ swap(s[k], s[k-1]); ans++; } break; } } }else { int target = -s[i]; for(int j = i+1; j < (int)s.size(); ++j){ if(s[j] == target){ for(int k = j; k > i; --k){ swap(s[k], s[k-1]); ans++; } break; } } } } 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...