Submission #262013

#TimeUsernameProblemLanguageResultExecution timeMemory
262013tiberiuArranging Shoes (IOI19_shoes)C++14
50 / 100
1089 ms14840 KiB
#include "shoes.h" #include <vector> using namespace std; long long count_swaps(std::vector<int> s) { int n = s.size() / 2; vector<int>* f = new vector<int>[2 * n + 1]() + n; for (int i = 0; i < 2 * n; i++) f[s[i]].push_back(i); vector<int> p(2 * n); for (int i = 1; i <= n; i++) { int j = 0; while (j < f[i].size()) { p[f[i][j]] = f[-i][j]; p[f[-i][j]] = f[i][j]; j++; } } long long ans = 0; for (int i = 0; i < 2 * n; i++) { if (p[i] < i) continue; if (s[p[i]] < s[i]) ans++; for (int j = i + 1; j < p[i]; j++) ans += (p[j] > i); } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:16:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while (j < f[i].size()) {
                ~~^~~~~~~~~~~~~
#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...