Submission #1030242

#TimeUsernameProblemLanguageResultExecution timeMemory
1030242enderArranging Shoes (IOI19_shoes)C++17
10 / 100
1 ms600 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(int i = 1; i <= n; ++i) p.push_back(i); long long ans = 1e18; do{ long long cnt = 0; vector<int> curr; // same size as s 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(s[i] == curr[i]) continue; for(int j = i+1; j < s.size(); ++j){ if(s[j] == curr[i]){ for(int k = j; k > i; --k){ swap(s[k], s[k-1]); cnt++; } break; } } }else { // debe ser zapato derecho if(s[i] == s[i-1] * -1) continue; int target = s[i-1] * -1; for(int j = i+1; j < s.size(); ++j){ if(s[j] == target){ for(int k = j; k > i; --k){ swap(s[k], s[k-1]); cnt++; } break; } } } } ans = min(cnt, ans); } while (next_permutation(p.begin(), p.end())); return ans; }

Compilation message (stderr)

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