Submission #670032

#TimeUsernameProblemLanguageResultExecution timeMemory
670032haxormanArranging Shoes (IOI19_shoes)C++14
10 / 100
1 ms300 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; long long count_swaps(vector<int> vec) { map<int,vector<int>> pos; for (int i = 0; i < vec.size(); ++i) { pos[vec[i]].push_back(i); } int ans = 0; for (int i = 0; i < vec.size() - 1; ++i) { /* cout << vec[i] << "\n"; for (auto x : pos[-vec[i]]) { cout << x << ' '; } cout << "\n---\n"; */ auto it = upper_bound(pos[-vec[i]].begin(), pos[-vec[i]].end(), i); ans += *it - i; if (vec[i] < 0) { --ans; } } return ans; }

Compilation message (stderr)

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