Submission #423578

#TimeUsernameProblemLanguageResultExecution timeMemory
423578schseArranging Shoes (IOI19_shoes)C++17
50 / 100
1121 ms273860 KiB
#include "shoes.h" #ifndef EVAL #include "grader.cpp" #endif #include <bits/stdc++.h> using namespace std; long long count_swaps(std::vector<int> s) { vector<int> posadd(s.size()); vector<bool> sorted(s.size(), false); vector<queue<int>> pleft(s.size() + 1), pright(s.size() + 1); iota(posadd.begin(), posadd.end(), 0); long long numswaps = 0; for (int i = 0; i < s.size(); i++) (s[i] > 0 ? pright : pleft)[abs(s[i])].push(i); for (int e, i = 0; i < s.size(); i++) { if (sorted[i]) continue; (s[i] > 0 ? pright : pleft)[abs(s[i])].pop(); e = (s[i] < 0 ? pright : pleft)[abs(s[i])].front(); (s[i] < 0 ? pright : pleft)[abs(s[i])].pop(); sorted[i] = sorted[e] = true; for (int c = i + 1; c < e; c++) posadd[c]++; numswaps += posadd[e] - posadd[i] - 1; if (s[i] > 0) numswaps++; } return numswaps; }

Compilation message (stderr)

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