제출 #1030490

#제출 시각아이디문제언어결과실행 시간메모리
1030490enderArranging Shoes (IOI19_shoes)C++17
30 / 100
1094 ms5556 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; long long count_swaps(std::vector<int> s) { int n = s.size()/2; vector<int> p; for(const auto &i : s) if(i > 0) p.push_back(i); //for(int i = 1; i <= n; ++i) p.push_back(i); sort(p.begin(), p.end()); long long ans = 1e18; do{ long long cnt = 0; vector<int> curr; // same size as s vector<int> current_s(s.begin(), s.end()); for(int i = 0; i < n; ++i){ curr.push_back(-p[i]); curr.push_back(p[i]); } for(int i = 0; i < s.size(); ++i){ if(i%2 == 0){ // debe ser zapato izquierdo if(current_s[i] == curr[i]) continue; for(int j = i+1; j < s.size(); ++j){ if(current_s[j] == curr[i]){ for(int k = j; k > i; --k){ swap(current_s[k], current_s[k-1]); cnt++; } break; } } }else { // debe ser zapato derecho if(current_s[i] == current_s[i-1] * -1) continue; int target = current_s[i-1] * -1; for(int j = i+1; j < s.size(); ++j){ if(current_s[j] == target){ for(int k = j; k > i; --k){ swap(current_s[k], current_s[k-1]); cnt++; } break; } } } } ans = min(cnt, ans); } while (next_permutation(p.begin(), p.end())); return ans; }

컴파일 시 표준 에러 (stderr) 메시지

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:25:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |   for(int i = 0; i < s.size(); ++i){
      |                  ~~^~~~~~~~~~
shoes.cpp:31:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |    for(int j = i+1; j < s.size(); ++j){
      |                     ~~^~~~~~~~~~
shoes.cpp:54:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |    for(int j = i+1; j < s.size(); ++j){
      |                     ~~^~~~~~~~~~
#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...