제출 #387482

#제출 시각아이디문제언어결과실행 시간메모리
387482kimbj0709Arranging Shoes (IOI19_shoes)C++14
30 / 100
151 ms19048 KiB
#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) 메시지

shoes.cpp: In function 'std::vector<int> merge_sort(std::vector<int>)':
shoes.cpp:10:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |   for(int i=0;i<vect1.size()/2;i++){
      |               ~^~~~~~~~~~~~~~~
shoes.cpp:13:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |   for(int i=vect1.size()/2;i<vect1.size();i++){
      |                            ~^~~~~~~~~~~~~
shoes.cpp:23:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |   for(int i=0;i<vect1.size();i++){
      |               ~^~~~~~~~~~~~~
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:39:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |   for(int i=0;i<s.size();i++){
      |               ~^~~~~~~~~
shoes.cpp:47:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   for(int i=0;i<nexts.size();i++){
      |               ~^~~~~~~~~~~~~
#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...