# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
387482 | kimbj0709 | Arranging Shoes (IOI19_shoes) | C++14 | 151 ms | 19048 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
#include<bits/stdc++.h>
using namespace std;
long long int ans = 0;
vector<int> merge_sort(vector<int> vect1){
if(vect1.size()<=1){
return vect1;
}
vector<int> left,right;
for(int i=0;i<vect1.size()/2;i++){
left.push_back(vect1[i]);
}
for(int i=vect1.size()/2;i<vect1.size();i++){
right.push_back(vect1[i]);
}
left = merge_sort(left);
right = merge_sort(right);
vector<int> curr;
left.push_back(INT_MAX);
right.push_back(INT_MAX);
reverse(left.begin(),left.end());
reverse(right.begin(),right.end());
for(int i=0;i<vect1.size();i++){
if(left.back()<right.back()){
curr.push_back(left.back());
left.pop_back();
}
else{
ans += left.size()-1;
curr.push_back(right.back());
right.pop_back();
}
}
return curr;
}
long long count_swaps(std::vector<int> s) {
int n = s.size();
vector<vector<int> > nexts(s.size()*2+100);
for(int i=0;i<s.size();i++){
if(s[i]>0){
nexts[s[i]].push_back(i);
}
else{
nexts[-2*s[i]].push_back(i);
}
}
for(int i=0;i<nexts.size();i++){
reverse(nexts[i].begin(),nexts[i].end());
}
vector<int> treated(s.size(),0);
int currpos = 0;
vector<int> positions(n,-1);
for(int i=0;i<n;i++){
if(treated[i]==1){
continue;
}
if(s[i]<0){
positions[i] = currpos;
positions[nexts[s[i]*-1].back()] = currpos+1;
treated[nexts[s[i]*-1].back()] = 1;
nexts[s[i]*-2].pop_back();
nexts[s[i]*-1].pop_back();
}
else{
positions[i] = currpos+1;
positions[nexts[s[i]*2].back()] = currpos;
treated[nexts[s[i]*2].back()] = 1;
nexts[s[i]*2].pop_back();
nexts[s[i]].pop_back();
}
currpos += 2;
}
merge_sort(positions);
return ans;
}
/*int main(){
int n;
cin >> n;
vector<int> vect1;
int input;
for(int i=0;i<2*n;i++){
cin >> input;
vect1.push_back(input);
}
cout << count_swaps(vect1);
}
*/
컴파일 시 표준 에러 (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... |